Coder Social home page Coder Social logo

3368aa / toasts.forms.plugin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from egorbo/toasts.forms.plugin

0.0 0.0 0.0 5.93 MB

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

License: MIT License

C# 99.92% Batchfile 0.08%

toasts.forms.plugin's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.