Plugin.LocalNotification
9.2.0
See the version list below for details.
Install-Package Plugin.LocalNotification -Version 9.2.0
dotnet add package Plugin.LocalNotification --version 9.2.0
<PackageReference Include="Plugin.LocalNotification" Version="9.2.0" />
paket add Plugin.LocalNotification --version 9.2.0
#r "nuget: Plugin.LocalNotification, 9.2.0"
// Install Plugin.LocalNotification as a Cake Addin
#addin nuget:?package=Plugin.LocalNotification&version=9.2.0
// Install Plugin.LocalNotification as a Cake Tool
#tool nuget:?package=Plugin.LocalNotification&version=9.2.0
Plugin.LocalNotification
The local notification plugin provides a way to show local notifications from Xamarin.Forms apps.
Setup
Plugin.LocalNotification
Available on NuGet: https://www.nuget.org/packages/Plugin.LocalNotification- Install into your platform-specific projects (iOS/Android), and any .NET Standard 2.0/2.1 projects required for your app.
- Must Use Xamarin.Forms 4.5.0.356 or above.
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+
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
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
- Thank you for the Icons by DinosoftLabs and Iconic Hub
- Thank you for the sound file by Notification sounds
- Thank you for the tutorial video by Gerald Versluis
Product | Versions |
---|---|
.NET | net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios 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 |
-
.NETStandard 2.0
- Newtonsoft.Json (>= 13.0.1)
-
MonoAndroid 10.0
- Newtonsoft.Json (>= 13.0.1)
- Xamarin.AndroidX.Core (>= 1.6.0.3)
-
Xamarin.iOS 1.0
- Newtonsoft.Json (>= 13.0.1)
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 Xamarin Forms and .Net Maui apps .
|
Version | Downloads | Last updated | |
---|---|---|---|
10.0.0-preview02 | 65 | 6/27/2022 | |
10.0.0-preview01 | 44 | 6/25/2022 | |
9.2.1-preview05 | 96 | 6/10/2022 | |
9.2.1-preview04 | 139 | 5/23/2022 | |
9.2.1-preview03 | 143 | 5/18/2022 | |
9.2.1-preview02 | 114 | 5/5/2022 | |
9.2.1-preview01 | 178 | 3/17/2022 | |
9.2.0 | 11,355 | 2/8/2022 | |
9.2.0-preview03 | 88 | 2/6/2022 | |
9.2.0-preview02 | 80 | 2/5/2022 | |
9.2.0-preview01 | 88 | 2/4/2022 | |
9.1.3 | 1,177 | 1/30/2022 | |
9.1.2 | 3,893 | 1/3/2022 | |
9.1.1 | 421 | 12/23/2021 | |
9.1.0 | 4,902 | 11/22/2021 | |
9.1.0-preview05 | 196 | 11/11/2021 | |
9.1.0-preview03 | 234 | 11/1/2021 | |
9.1.0-preview02 | 251 | 10/31/2021 | |
9.1.0-preview01 | 186 | 10/27/2021 | |
9.0.1 | 3,084 | 10/25/2021 | |
9.0.0 | 3,842 | 9/17/2021 | |
9.0.0-preview04 | 393 | 8/25/2021 | |
9.0.0-preview03 | 225 | 8/22/2021 | |
9.0.0-preview02 | 242 | 8/11/2021 | |
9.0.0-preview01 | 377 | 7/23/2021 | |
8.0.2 | 5,401 | 7/21/2021 | |
8.0.1 | 718 | 7/20/2021 | |
7.0.0 | 868 | 7/17/2021 | |
6.1.0 | 10,598 | 6/3/2021 | |
6.0.0 | 1,987 | 5/14/2021 | |
5.2.0 | 20,532 | 12/17/2020 | |
5.1.1 | 2,564 | 11/11/2020 | |
5.1.0 | 5,275 | 9/28/2020 | |
5.0.7 | 819 | 9/24/2020 | |
5.0.6 | 6,038 | 7/21/2020 | |
5.0.4 | 4,756 | 5/18/2020 | |
5.0.3 | 3,198 | 4/1/2020 | |
5.0.2 | 553 | 3/26/2020 | |
5.0.1 | 1,865 | 2/21/2020 | |
5.0.0 | 1,003 | 2/16/2020 | |
5.0.0-rc1 | 414 | 1/14/2020 | |
5.0.0-preview06 | 409 | 1/7/2020 | |
5.0.0-preview01 | 772 | 9/12/2019 | |
4.1.4 | 7,188 | 2/16/2020 | |
4.1.3 | 1,402 | 2/5/2020 | |
4.1.2 | 2,420 | 1/6/2020 | |
4.0.8 | 14,700 | 10/21/2019 | |
4.0.7 | 2,579 | 10/6/2019 | |
4.0.6 | 6,246 | 9/12/2019 | |
4.0.5 | 6,906 | 8/1/2019 | |
4.0.4 | 2,653 | 7/18/2019 | |
4.0.3 | 1,871 | 6/25/2019 | |
4.0.2 | 902 | 6/18/2019 | |
4.0.1 | 1,329 | 6/6/2019 | |
3.0.2 | 3,601 | 5/20/2019 | |
3.0.1 | 2,431 | 4/23/2019 | |
3.0.0 | 1,899 | 3/28/2019 | |
2.0.7 | 6,874 | 2/3/2019 | |
2.0.6 | 508 | 1/31/2019 | |
2.0.5 | 1,285 | 12/2/2018 | |
2.0.4 | 815 | 11/27/2018 | |
2.0.3 | 1,569 | 10/16/2018 | |
2.0.1 | 594 | 10/15/2018 | |
2.0.0 | 755 | 10/12/2018 | |
1.0.1 | 607 | 9/27/2018 | |
1.0.0 | 691 | 9/25/2018 |