Plugin.LocalNotification 10.0.0-preview01

.NET 6.0 .NET Standard 2.0
This is a prerelease version of Plugin.LocalNotification.
There is a newer version of this package available.
See the version list below for details.
Install-Package Plugin.LocalNotification -Version 10.0.0-preview01
dotnet add package Plugin.LocalNotification --version 10.0.0-preview01
<PackageReference Include="Plugin.LocalNotification" Version="10.0.0-preview01" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Plugin.LocalNotification --version 10.0.0-preview01
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Plugin.LocalNotification, 10.0.0-preview01"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Plugin.LocalNotification as a Cake Addin
#addin nuget:?package=Plugin.LocalNotification&version=10.0.0-preview01&prerelease

// Install Plugin.LocalNotification as a Cake Tool
#tool nuget:?package=Plugin.LocalNotification&version=10.0.0-preview01&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

icon64

CI NuGet NuGet

Plugin.LocalNotification

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

Setup

Platform Support

Feature Xamarin.iOS Xamarin.Android
Required SDK >= 10 >= API 19
Title
Description
Subtitle
Scheduled
Custom Sounds
Images
Notification Actions
Clear Delivered Notifications
Get Pending Notifications
Get Delivered Notifications

Android Notes:

Project should target Android framework 12.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.
    Schedule = 
    {
        NotifyTime = DateTime.Now.AddSeconds(30) // Used for Scheduling local notification, if not specified notification will show immediately.
    }
};
await NotificationCenter.Current.Show(notification);

Or with Notification Request Builder

await NotificationCenter.Current.Show((notification) => notification                     
			.WithScheduleOptions((schedule) => schedule
					.NotifyAt(DateTime.Now.AddSeconds(30)) // Used for Scheduling local notification, if not specified notification will show immediately.
					.Build())
                        .WithTitle("Test Title")
                        .WithDescription("Test Description")
                        .WithReturningData("Dummy Data") // Returning data when tapped on notification.
                        .WithNotificationId(100)
                        .Create());

With platform specific options

await NotificationCenter.Current.Show((notification) => notification
                    .WithScheduleOptions((schedule) => schedule
					.NotifyAt(DateTime.Now.AddSeconds(30))
					.Build())
                    .WithAndroidOptions((android) => android
                         .WithAutoCancel(true)
                         .WithChannelId("General")
                         .WithPriority(NotificationPriority.High)
                         .WithOngoingStatus(true)
                         .Build())
                    .WithiOSOptions((ios) => ios
                        .WithForegroundAlertStatus(true)
                        .WithForegroundSoundStatus(true)
                        .Build())
                    .WithReturningData("Dummy Data")
                    .WithTitle("Test Title")
                    .WithDescription("Test Description")
                    .WithNotificationId(100)
                    .Create());

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(NotificationEventArgs e)
    	{
		// your code goes here
	}
}

Notification received event

On iOS this event is fired only when the app is in foreground

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

		// Local Notification received event listener
		NotificationCenter.Current.NotificationReceived += OnLocalNotificationReceived;

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

Platform Specific Notes

Android

Project should target Android framework 12.0+

image

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 bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            global::Xamarin.Forms.Forms.Init();

            // Ask the user for permission to show notifications on iOS 10.0+ at startup.
            // If not asked at startup, user will be asked when showing the first notification.
            Plugin.LocalNotification.NotificationCenter.AskPermission();

            LoadApplication(new App());

            return base.FinishedLaunching(app, options);
        }

	public override void WillEnterForeground(UIApplication uiApplication)
        {
            Plugin.LocalNotification.NotificationCenter.ResetApplicationIconBadgeNumber(uiApplication);
        }
}

Screen Record

<img src="https://raw.githubusercontent.com/thudugala/Plugin.LocalNotification/60c9342ba866b1af1278c273f3d41a168901e4ff/Screenshots/screenRecord.gif" alt="Screen Record" width="512px" >

Video

Local Push Notifications in Xamarin.Forms

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 <b>iOS</b> and <b>Android</b> 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.

Thank you

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-android31.0 net6.0-ios net6.0-ios15.2 net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid monoandroid10.0
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios xamarinios10
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (7)

Showing the top 5 NuGet packages that depend on Plugin.LocalNotification:

Package Downloads
Abel.Core

Abel mobile framework is a Xamarin library to help build cross-platform mobile apps from Abel ERP software

Fluker

This package contains common classes and interfaces that are used in other Fluker controls.

Fluker.Media

This package contains classes, interfaces, controls and utility for support media like video, pdf and images in the app. It depends on Fluker

Fluker.Maps

This package contains support to custom integrations of the system Map platform. It depends on Fluker.Base

Fluker.Account.Email

This package contains classes, interfaces, controls and utility for support Users (Login, Registrarion) through email in the app. It depends on Fluker

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on Plugin.LocalNotification:

Repository Stars
thudugala/Plugin.LocalNotification
The local notification plugin provides a way to show local notifications from .Net MAUI and Xamarin Forms apps .
Version Downloads Last updated
10.0.1 295 8/4/2022
10.0.0 294 8/1/2022
10.0.0-preview02 196 6/27/2022
10.0.0-preview01 72 6/25/2022
9.2.1-preview05 127 6/10/2022
9.2.1-preview04 162 5/23/2022
9.2.1-preview03 163 5/18/2022
9.2.1-preview02 121 5/5/2022
9.2.1-preview01 211 3/17/2022
9.2.0 14,768 2/8/2022
9.2.0-preview03 93 2/6/2022
9.2.0-preview02 85 2/5/2022
9.2.0-preview01 93 2/4/2022
9.1.3 1,446 1/30/2022
9.1.2 4,496 1/3/2022
9.1.1 445 12/23/2021
9.1.0 5,468 11/22/2021
9.1.0-preview05 201 11/11/2021
9.1.0-preview03 239 11/1/2021
9.1.0-preview02 256 10/31/2021
9.1.0-preview01 191 10/27/2021
9.0.1 3,366 10/25/2021
9.0.0 3,966 9/17/2021
9.0.0-preview04 398 8/25/2021
9.0.0-preview03 226 8/22/2021
9.0.0-preview02 243 8/11/2021
9.0.0-preview01 378 7/23/2021
8.0.2 5,693 7/21/2021
8.0.1 733 7/20/2021
7.0.0 886 7/17/2021
6.1.0 11,403 6/3/2021
6.0.0 2,005 5/14/2021
5.2.0 21,275 12/17/2020
5.1.1 2,580 11/11/2020
5.1.0 5,315 9/28/2020
5.0.7 827 9/24/2020
5.0.6 6,100 7/21/2020
5.0.4 4,769 5/18/2020
5.0.3 3,233 4/1/2020
5.0.2 568 3/26/2020
5.0.1 1,874 2/21/2020
5.0.0 1,012 2/16/2020
5.0.0-rc1 415 1/14/2020
5.0.0-preview06 410 1/7/2020
5.0.0-preview01 773 9/12/2019
4.1.4 7,229 2/16/2020
4.1.3 1,421 2/5/2020
4.1.2 2,440 1/6/2020
4.0.8 14,971 10/21/2019
4.0.7 2,615 10/6/2019
4.0.6 6,265 9/12/2019
4.0.5 7,022 8/1/2019
4.0.4 2,690 7/18/2019
4.0.3 1,900 6/25/2019
4.0.2 917 6/18/2019
4.0.1 1,359 6/6/2019
3.0.2 3,645 5/20/2019
3.0.1 2,460 4/23/2019
3.0.0 1,933 3/28/2019
2.0.7 6,982 2/3/2019
2.0.6 516 1/31/2019
2.0.5 1,307 12/2/2018
2.0.4 833 11/27/2018
2.0.3 1,602 10/16/2018
2.0.1 602 10/15/2018
2.0.0 771 10/12/2018
1.0.1 615 9/27/2018
1.0.0 699 9/25/2018