• Stars
    star
    278
  • Rank 147,715 (Top 3 %)
  • Language
    C#
  • License
    MIT License
  • Created over 9 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A plugin for Xamarin and Windows - it unites Crouton (Android), TWMessageBarManager (iOS) and my toast notificator for WP8.

Toasts Notification Plugin for Xamarin and Windows

A simple way of showing notifications inside your Xamarin or Windows application. In windows phone world we call them "Toasts". This plugin uses the platforms native toast / notification API's.

Setup and usage

Setup

Platform Support

Platform Supported Version
Xamarin.iOS No
Xamarin.iOS Unified Yes iOS 10+
Xamarin.Android Yes API 16+ (AppCompat Only)
Windows Phone Silverlight No
Windows Phone RT No
Windows Store RT No
Windows 10 UWP Yes 10+
Xamarin.Mac No

Now uses .NET Standard 1.3, does support PCL 111.

iOS Support Version 3+ of this plugin requires iOS10 to display the toast notification. If you require support for iOS7+ then please use version 2.0.4.

I you want to use the latest plugin with a version less than iOS 10 you can hook into the ReceivedLocalNotification in the AppDelegate to display an Alert.

Setup

In your iOS, Android, WinRT and UWP projects please call:

DependencyService.Register<ToastNotification>(); // Register your dependency
ToastNotification.Init();

// If you are using Android you must pass through the activity
ToastNotification.Init(this);

If you are using Xamarin Forms, you must do this AFTER your call to Xamarin.Forms.Init();

Usage

Use dependency service in order to resolve IToastNotificator.

var notificator = DependencyService.Get<IToastNotificator>();

var options = new NotificationOptions()
            {
                Title = "Title",
                Description = "Description"
            };

var result = await notificator.Notify(options);

The result that is returned is a NotificationResult with an Action inside with one of the following values.

[Flags]
public enum NotificationAction
{
    Timeout = 1, // Hides by itself
    Clicked = 2, // User clicked on notification
    Dismissed = 4, // User manually dismissed notification
    ApplicationHidden = 8, // Application went to background
    Failed = 16 // When failed to display the toast
}

If you want the Clicked NotificationAction you must set IsClickable = true in the NotificationOptions.

Permissions

In iOS you must request permission to show local notifications first since it is a user interrupting action.

// Request Permissions
if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0))
{
    // Request Permissions
    UNUserNotificationCenter.Current.RequestAuthorization(UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound, (granted, error) =>
    {
        // Do something if needed
    });
}
else if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
{
    var notificationSettings = UIUserNotificationSettings.GetSettingsForTypes(
    UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound, null);

    app.RegisterUserNotificationSettings(notificationSettings);
}

Contributors

Thanks!

License

Licensed under MIT

More Repositories

1

SimdJsonSharp

C# bindings for lemire/simdjson (and full C# port)
C#
643
star
2

Disasmo

VS2022 Add-in. Click on any method or class to see what .NET Core's JIT generates for them (ASM).
C#
638
star
3

CrossChat-Xamarin.Forms

A chat application implemented using Xamarin.Forms and DDD + MVVM
C#
319
star
4

Xamarin.GradleBindings

VS add-in. Creates Xamarin.Android Binding Projects using gradle
C#
146
star
5

Xamaridea

Visual Studio extension. Opens *.axml/xml files in IDEA or Android Studio (Xamarin.Android)
C#
78
star
6

IntrinsicsPlayground

My toys to play with SSE/AVX in pure C# (.NET Core 2.1)
C#
64
star
7

XamarinWithUnityApp

A Xamarin app (Android) with Unity as a library (aar)
C#
46
star
8

ARKitXamarinDemo

ARKit + UrhoSharp + Xamarin
C#
45
star
9

CppPinvokeGenerator

A simple pinvoke generator based on CppAst to generate C# for C++
C#
32
star
10

Xamarin.Android-vs-Java

Performance comparison between Xamarin.Android+C# vs (Dalvik or ART)+Java
Java
25
star
11

HelloIL

A simple .NET 6.0 Hello World written in pure IL
19
star
12

UrhoAssetImporter

HLSL
16
star
13

left-pad-net

left-pad for C# via nuget
C#
13
star
14

PrejitAll

A helper tool to prejit everything in a given folder
C#
10
star
15

MonoNET5Sample

C#
9
star
16

DeclarativeVisualStates

Just trying to port VisualStateManager from Xaml (Wpf) to Android XML (Java)
Java
9
star
17

EgorBo.github.io

My blog https://egorbo.com
HTML
8
star
18

MatieBot

C#
7
star
19

MvvmNavigationToolkit

Navigation toolkit for Windows Phone & Windows Store apps
C#
7
star
20

SimpleUrhoRoomScene

A simple scene made with Blender and UrhoSharp
C#
6
star
21

UrhoArkitTemplate

Demo for https://blog.xamarin.com/bring-3d-models-life-augmented-reality-urhosharp/
C#
6
star
22

NtlmHttpHandler

NtlmHttpHandler allows to create NTLM-friendly http handlers for HttpClient.
C#
6
star
23

JitDisasmSample

COMPlus_JitDisasm usage example
Shell
4
star
24

ARVRWorkshop

C#
3
star
25

MyApartments

a dump of my apartments from HoloLens + UrhoSharp
C#
2
star
26

OpenALRP.SharpExperiments

OpenALRP Xamarin Workbook
2
star
27

HoloLightsaber

C#
2
star
28

JavaSSLStream

Just some tests
C
2
star
29

MonoMergeHelper

A tool to merge mono with CoreFX and CoreRT
C#
1
star