Local Notifications
Getting Started
Section titled “Getting Started” Operating Systems
Android
iOS
Local notifications allow your app to alert users even when the app is not in the foreground. Use them to notify about completed background tasks, BLE events, geofence triggers, and more.
Requesting Access
Section titled “Requesting Access”INotificationManager notifications; // injected
// Basic notification permissionvar access = await notifications.RequestAccess();
// With additional capabilitiesvar access = await notifications.RequestAccess( AccessRequestFlags.Notification | AccessRequestFlags.TimeSensitivity | AccessRequestFlags.LocationAware);| Flag | Description |
|---|---|
Notification | Basic notification permission |
TimeSensitivity | iOS Time Sensitive notifications |
LocationAware | Required for geofence-triggered notifications |
Handling Notification Taps
Section titled “Handling Notification Taps”Implement INotificationDelegate to respond when a user taps a notification.
public class MyNotificationDelegate : INotificationDelegate{ public Task OnEntry(NotificationResponse response) { var notification = response.Notification; var actionId = response.ActionIdentifier; var text = response.Text; // from text reply actions
// Access custom payload if (notification.Payload.TryGetValue("orderId", out var orderId)) { // Navigate to order details }
return Task.CompletedTask; }}Registration
Section titled “Registration”services.AddNotifications<MyNotificationDelegate>();Platform Notes
Section titled “Platform Notes”Android
Section titled “Android”To handle notification taps properly on Android, add an intent filter to your MainActivity:
[Activity( Theme = "@style/Maui.SplashTheme", MainLauncher = true, LaunchMode = LaunchMode.SingleTop)][IntentFilter( new[] { Shiny.ShinyNotificationIntents.NotificationClickAction }, Categories = new[] { "android.intent.category.DEFAULT" })]public class MainActivity : MauiAppCompatActivity{}