Push Notifications
Getting Started
Section titled “Getting Started”| GitHub | |
| Downloads |
Push notifications are server-driven notifications delivered via platform services (APNs on iOS / macOS, FCM on Android, WNS on Windows, Web Push on Blazor). Shiny provides a unified API that works across providers while giving you access to native capabilities. Azure Notification Hubs is supported on iOS, Mac Catalyst, macOS, tvOS, Android, and Windows.
Platform Notes
Section titled “Platform Notes”| Platform | Provider | Package |
|---|---|---|
| iOS | APNs (direct or via Firebase) | Shiny.Push |
| tvOS | APNs (silent / badge only) | Shiny.Push |
| macOS | APNs | Shiny.Push |
| Android | Firebase Cloud Messaging | Shiny.Push |
| Windows | Windows Notification Service | Shiny.Push |
| Blazor WebAssembly | Web Push (VAPID) | Shiny.Push |
- MyApp/
1using Shiny.Push;23namespace MyApp.Delegates;45public partial class MyPushDelegate : PushDelegate6{7 public override async Task OnEntry(PushNotification notification)8 {9 }1011 public override async Task OnReceived(PushNotification notification)12 {13 }1415 public override async Task OnNewToken(string token)16 {17 }1819 public override async Task OnUnRegistered(string token)20 {21 }22}Android Firebase Configuration
Section titled “Android Firebase Configuration”Android Activity Setup
Section titled “Android Activity Setup”Add the intent filter for handling notification taps:
[Activity( Theme = "@style/Maui.SplashTheme", MainLauncher = true, LaunchMode = LaunchMode.SingleTop)][IntentFilter( new[] { Shiny.ShinyPushIntents.NotificationClickAction }, Categories = new[] { "android.intent.category.DEFAULT" })]public class MainActivity : MauiAppCompatActivity{}IPushManager
Section titled “IPushManager”IPushManager handles registration and token management.
IPushManager pushManager; // injected
// Request access and get tokenvar result = await pushManager.RequestAccess();if (result.Status == AccessState.Available){ var token = result.RegistrationToken; // Send token to your server}
// Current tokensvar regToken = pushManager.RegistrationToken; // Provider tokenvar nativeToken = pushManager.NativeRegistrationToken; // Raw APNs/FCM token
// Unregisterawait pushManager.UnRegister();Push Delegate
Section titled “Push Delegate”Implement IPushDelegate (or extend PushDelegate) to handle push events.
public class MyPushDelegate : PushDelegate{ readonly ILogger<MyPushDelegate> logger;
public MyPushDelegate(ILogger<MyPushDelegate> logger) { this.logger = logger; }
public override Task OnEntry(PushNotification notification) { // User tapped the notification this.logger.LogInformation("Push tapped: {Title}", notification.Notification?.Title);
// Access data payload foreach (var (key, value) in notification.Data) { this.logger.LogInformation("{Key}: {Value}", key, value); } return Task.CompletedTask; }
public override Task OnReceived(PushNotification notification) { // Push received (background or foreground) this.logger.LogInformation("Push received: {Title}", notification.Notification?.Title); return Task.CompletedTask; }
public override Task OnNewToken(string token) { // Token changed - send to your server this.logger.LogInformation("New push token: {Token}", token); return Task.CompletedTask; }
public override Task OnUnRegistered(string token) { // Unregistered - notify your server this.logger.LogInformation("Push unregistered: {Token}", token); return Task.CompletedTask; }}Registration
Section titled “Registration”services.AddPush<MyPushDelegate>();Tags allow you to target push notifications to specific groups of users. Tag support depends on your push provider.
IPushManager pushManager; // injected
if (pushManager.IsTagsSupport()){ await pushManager.Tags.SetTags("premium", "news"); await pushManager.Tags.AddTag("sports"); await pushManager.Tags.RemoveTag("news");
var tags = pushManager.Tags.RegisteredTags;
await pushManager.Tags.ClearTags();}
// Or use convenience extensionsawait pushManager.TrySetTags("premium", "news");var tags = pushManager.TryGetTags();iOS Customization
Section titled “iOS Customization”Implement IApplePushDelegate for iOS-specific control over notification presentation.
#if IOSpublic class MyPushDelegate : PushDelegate, IApplePushDelegate{ public UNNotificationPresentationOptions? GetPresentationOptions(PushNotification notification) { // Control how notifications appear when app is in foreground return UNNotificationPresentationOptions.Banner | UNNotificationPresentationOptions.Sound | UNNotificationPresentationOptions.Badge; }
public UIBackgroundFetchResult? GetFetchResult(PushNotification notification) { return UIBackgroundFetchResult.NewData; }}#endifAndroid Customization
Section titled “Android Customization”Cast PushNotification to AndroidPushNotification for full control.
#if ANDROIDpublic override Task OnReceived(PushNotification notification){ if (notification is AndroidPushNotification androidPush) { // Use the default builder and send androidPush.SendDefault(1001);
// Or customize the notification var builder = androidPush.CreateBuilder(); builder .SetContentTitle("Custom Title") .SetSmallIcon(Resource.Mipmap.appicon); androidPush.Notify(1001, builder); } return Task.CompletedTask;}#endif

