Plugin.LocalNotification
9.2.0
See the version list below for details.
dotnet add package Plugin.LocalNotification --version 9.2.0
NuGet\Install-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 Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. monoandroid10.0 is compatible. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. xamarinios10 is compatible. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.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 (6)
Showing the top 5 NuGet packages that depend on Plugin.LocalNotification:
Package | Downloads |
---|---|
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 |
|
Fluker.Shop.Stripe
This package contains classes, interfaces, controls and utility for integrate a shop system like cart and payments with credit card in the app. It depends on Fluker. |
GitHub repositories (2)
Showing the top 2 popular GitHub repositories that depend on Plugin.LocalNotification:
Repository | Stars |
---|---|
bitfoundation/bitplatform
Build all of your apps using what you already know and love ❤️
|
|
LiamMorrow/LiftLog
A cross platform app for tracking your lifts in the gym
|
Version | Downloads | Last updated |
---|---|---|
11.1.4 | 61,422 | 7/8/2024 |
11.1.3 | 23,411 | 6/5/2024 |
11.1.2 | 18,546 | 4/14/2024 |
11.1.1 | 19,326 | 2/26/2024 |
11.1.0 | 4,295 | 2/21/2024 |
10.2.0-preview01 | 474 | 2/21/2024 |
10.1.8 | 102,352 | 6/29/2023 |
9.2.0 | 44,764 | 2/8/2022 |
8.0.2 | 7,810 | 7/21/2021 |
7.0.0 | 1,515 | 7/17/2021 |
6.1.0 | 26,379 | 6/3/2021 |
5.2.0 | 28,781 | 12/17/2020 |