Skip to content

Platform Specific

When a push notification arrives, your PushDelegate receives a PushNotification object. On each platform, this is actually a platform-specific subclass with additional native capabilities. Cast to AndroidPushNotification or ApplePushNotification to access them.

PropertyTypeDescription
DataIDictionary<string, string>Key/value data payload from the push message
NotificationNotification?Title and message (null for silent/data-only pushes)

Extends PushNotification with access to the native Firebase RemoteMessage and helper methods for displaying notifications.

PropertyTypeDescription
NativeMessageRemoteMessageThe raw Firebase Cloud Messaging message
ConfigFirebaseConfigThe Firebase configuration used by the app
PlatformAndroidPlatformAndroid platform utilities

Creates a pre-configured NotificationCompat.Builder from the push payload. The builder is set up with the title, body, icon, color, channel, and tap intent from the incoming message.

public override Task OnReceived(PushNotification notification)
{
if (notification is AndroidPushNotification android)
{
var builder = android.CreateBuilder();
// Customize further before sending
builder
.SetContentTitle("Custom Title")
.SetContentText("Custom body text")
.SetSmallIcon(Resource.Mipmap.appicon)
.SetAutoCancel(true);
android.Notify(1001, builder);
}
return Task.CompletedTask;
}

The builder automatically resolves:

  • Title & body from the notification payload
  • Small icon from the notification drawable resource, falling back to the app icon
  • Color from the notification color field mapped to an Android color resource
  • Channel from the notification channel ID or the default channel in FirebaseConfig
  • Tap intent from the click action or the default ShinyPushIntents.NotificationClickAction

Sends a notification using the Android NotificationManager.

android.Notify(notificationId, builder);
ParameterTypeDescription
notificationIdintUnique ID for the notification (use same ID to update)
builderNotificationCompat.BuilderThe configured notification builder

Convenience method that calls CreateBuilder() and Notify() in one step.

android.SendDefault(1001);
#if ANDROID
public override Task OnReceived(PushNotification notification)
{
if (notification is AndroidPushNotification android)
{
// Option 1: Send with all defaults from the push payload
android.SendDefault(1001);
// Option 2: Customize the notification before sending
var builder = android.CreateBuilder();
builder
.SetSmallIcon(Resource.Mipmap.appicon)
.SetPriority(NotificationCompat.PriorityHigh);
android.Notify(1001, builder);
// Option 3: Access the raw Firebase message
var raw = android.NativeMessage;
var messageId = raw.MessageId;
var sentTime = raw.SentTime;
}
return Task.CompletedTask;
}
#endif

Extends PushNotification with access to the raw APNs payload dictionary.

PropertyTypeDescription
RawPayloadNSDictionary?The raw APNs payload as an Objective-C dictionary

The RawPayload contains the full APNs JSON payload as an NSDictionary, giving you access to custom keys, the aps dictionary, and any provider-specific data.

#if IOS
public override Task OnReceived(PushNotification notification)
{
if (notification is ApplePushNotification apple)
{
if (apple.RawPayload != null)
{
// Access the aps dictionary
var aps = apple.RawPayload["aps"] as NSDictionary;
// Access custom keys
if (apple.RawPayload.TryGetValue(new NSString("customKey"), out var value))
{
var customValue = value.ToString();
}
}
}
return Task.CompletedTask;
}
#endif
KeyDescription
apsThe APNs payload dictionary (alert, badge, sound, content-available, etc.)
aps.alertAlert dictionary or string
aps.badgeBadge count
aps.soundSound file name
aps.content-available1 for silent/background push
aps.mutable-content1 for Notification Service Extension processing
public override Task OnReceived(PushNotification notification)
{
// Common data payload - works on all platforms
foreach (var (key, value) in notification.Data)
{
logger.LogInformation("Push data: {Key}={Value}", key, value);
}
// Platform-specific handling
#if ANDROID
if (notification is AndroidPushNotification android)
{
android.SendDefault(1001);
}
#elif IOS
if (notification is ApplePushNotification apple)
{
// Access raw APNs payload if needed
var raw = apple.RawPayload;
}
#endif
return Task.CompletedTask;
}