Push Notifications
Getting Started
Section titled “Getting Started” Frameworks
.NET
.NET MAUI
Blazor
Operating Systems
Android
iOS
macOS
Windows
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.
Platform Notes
Section titled “Platform Notes”| Platform | Provider | Package |
|---|---|---|
| iOS | APNs (direct or via Firebase) | 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.Blazor |
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.Push.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