Skip to content

Usage 3.0.2

Elvin (Tharindu) Thudugala edited this page Jun 6, 2019 · 1 revision

Platform Support

Platform Supported Version Notes
Xamarin.iOS Yes iOS 10+
Xamarin.Android Yes API 21+ Project should target Android framework 9.0+

Usage

Show local notification

var notification = new Plugin.LocalNotification.LocalNotification
{
    NotificationId = 100,
    Title = "Test",
    Description = "Test Description",
    ReturningData = "Dummy data", // Returning data when tapped on notification.
    NotifyTime = DateTime.Now.AddSeconds(30) // Used for Scheduling local notification, if not specified notification will show immediately.
};
NotificationCenter.Current.Show(notification);

Cancel a local notification

NotificationCenter.Current.Cancel(100);

Receive local notification tap event

public partial class App : Application
{
	public App()
	{
		InitializeComponent();

		// Local Notification tap event listener
		NotificationCenter.Current.NotificationTapped += OnLocalNotificationTapped;

		MainPage = new MainPage();
	}
	
	private void OnLocalNotificationTapped(LocalNotificationTappedEvent e)
    	{
		// your code goes here
	}
}

Platform Specific Notes

Android

Notification Icon must be set for notification to appear.

You can set the notification Icon by setting the following property from inside your Android project:

NotificationCenter.NotificationIconId = Resource.Drawable