Skip to content

The local notification plugin provides a way to show local notifications from Xamarin Forms apps .

License

Notifications You must be signed in to change notification settings

gvhung/Plugin.LocalNotification

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

121 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

icon

Build status

NuGet

3.0.2 Documentation

  • Please go to 3.0.2 Documentation, if you are referencing a version below 4.0.0.
  • Version 4.* has setup differences in Android if upgrading from version 3.*

2.0.7 Documentation

  • Please go to 2.0.7 Documentation, if you are referencing a version below 3.0.0.
  • Version 3.* has breaking changes if upgrading from version 2.*

Plugin.LocalNotification

The local notification plugin provides a way to show local notifications from Xamarin.Forms apps.

Setup

Platform Support

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

Usage

Show local notification

var notification = new NotificationRequest
{
    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);

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

Scheduled local notifications will persist after device reboot, if permission is set and SDK more than 5.0 Lollipop (API 21). You only need to do this if you plugin verion is below 4.0.3

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

Setup

To receive Local Notification tap event. Include the following code in the OnNewIntent() method of MainActivity:

public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
	protected override void OnCreate(Bundle savedInstanceState)
	{
	        .....
	        // Must create a Notification Channel when API >= 26
                // you can created multiple Notification Channels with different names.
                NotificationCenter.CreateNotificationChannel();		
		.....		
		LoadApplication(new App());
		.....	
		NotificationCenter.NotifyNotificationTapped(Intent);
	}

	protected override void OnNewIntent(Intent intent)
	{
		NotificationCenter.NotifyNotificationTapped(intent);
		base.OnNewIntent(intent);
	}
}

iOS

Setup

You must get permission from the user to allow the app to show local notifications. Also, To receive Local Notification tap event. Include the following code in the FinishedLaunching() method of AppDelegate:

public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
{        
	public override void WillEnterForeground(UIApplication uiApplication)
        {
            Plugin.LocalNotification.NotificationCenter.ResetApplicationIconBadgeNumber(uiApplication);
        }
}

Screen Record

Screen Record

Notification Channels

Setting up Notification Channels

Custom Sound

Notification with a Sound-File

SourceLink Support

In Visual Studio, confirm that SourceLink is enabled. Also, Turn off "Just My Code" since, well, this isn't your code.

https://docs.microsoft.com/en-us/dotnet/standard/library-guidance/sourcelink

Limitations

Only support iOS and Android for the moment.

Contributing

Contributions are welcome. Feel free to file issues and pull requests on the repo and they'll be reviewed as time permits.

Icon and Sound

Thank you for the Icon by DinosoftLabs and sound file by Notification sounds

About

The local notification plugin provides a way to show local notifications from Xamarin Forms apps .

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 100.0%