OSNotification class represents the push notification payload in OneSignal’s SDKs. Use it to access notification title, body, custom data, and platform-specific properties when handling notifications in your app.
Push notification payloads are limited to
4096 bytes. To avoid truncation, keep payloads under 3500 bytes. The additionalData field is limited to 2048 bytes.Accessing OSNotification in your app
All OneSignal SDKs provide notification events that return an OSNotification object:
- Android: Use the foreground lifecycle listener, the click listener, or a Notification Service Extension
- iOS: Use the foreground lifecycle listener, the click listener, or a
UNNotificationServiceExtension
promo_code value from additionalData inside a click listener:
addClickListener() Push.
Payload fields
The Android and iOS tables below list the native field names. Cross-platform SDKs expose the same payload with language-specific casing. Flutter uses
launchUrl instead of launchURL, and the Unity C# SDK uses PascalCase, such as AdditionalData and LaunchURL.Android fields
Access these as properties in Kotlin (notification.title) or as getters in Java (notification.getTitle()).
iOS fields
The iOS class also provides
parseWithApns, a method that converts a raw APNs payload into an OSNotification. Use it inside a UNNotificationServiceExtension. See Mobile Service Extensions.
Notification click events
Click listeners receive a click event with two properties: thenotification object described above, and a result describing what the user clicked. Register a listener with addClickListener(). The event class is INotificationClickEvent on Android and OSNotificationClickEvent on iOS.
SDK 3.x exposed click data as
OSNotificationAction with a type enum (Opened or ActionTaken). That enum is not available in SDK 5.x. Check result.actionId instead: it is null for a body tap and set to the button ID when an action button was clicked.Custom OneSignal payload structure
All OneSignal notifications include a special"custom" object in the payload:
This key is required for OneSignal SDKs to process the notification. If missing, notifications will not trigger click events or analytics. If you send pushes from another service to devices that also use OneSignal, filter by this key to prevent duplicate processing. See Push payload handling for guidance.
Move additionalData to APNs root
For iOS apps, you can placeadditionalData fields in the root of the APNs payload instead of inside the custom dictionary. This simplifies access in custom notification handlers.
1. Enable via the API
Use the Update an app API and set:
data
The data fields appear in the APNs root payload:
promo_code directly without checking the custom dictionary.
Restored notifications (Android)
The Android SDK automatically redisplays (restores) notifications that Android removed from the notification shade without the user dismissing or clicking them. Restore runs when the device reboots, when the app is updated, and when the app cold starts, such as after a force-quit. A notification is only restored when all of the following are true:- The user did not dismiss or click it.
- It is within its TTL (time-to-live), which defaults to 3 days. Notifications older than 7 days are never restored, even with a longer TTL.
- It is not still visible in the notification shade.
OSNotification property or API parameter to detect or disable restore. SDK version 3.x exposed a restoring flag on the notification payload. That flag was removed in SDK 4.0 and is not available in SDK 4.x or 5.x.
Prevent or clear restored notifications
- Set a shorter
ttlwhen sending. Notifications past their TTL are never restored. Use a short or0TTL for time-sensitive messages that should not reappear. - Clear notifications on app launch. Call
clearAllNotifications()when your app starts to remove all OneSignal notifications from the shade. Cleared notifications are marked as dismissed and are not restored again. To clear specific notifications, useremoveNotification()orremoveGroupedNotifications().
Push token formats
- iOS Push (APNs): 64 characters, hexadecimal only (0-9, a-f).
deviceToken.map {String(format: "%02x", $0)}.joined() - Android Push (FCM): Typically 163 characters, alphanumeric, may contain hyphens, colons, and underscores.
FAQ
What is the maximum payload size?
The total payload is limited to 4096 bytes, andadditionalData within it to 2048 bytes. Keep the total under 3500 bytes to avoid truncation.
How do I identify a OneSignal notification in the raw payload?
All OneSignal notifications include a"custom" object with an "i" key containing the notification ID. Check for this key to distinguish OneSignal notifications from those sent by other providers.
Why do old notifications reappear when the app opens on Android?
The Android SDK restores notifications that were force-removed from the notification shade, such as after a device reboot, app update, or force-quit. Notifications the user dismissed or clicked are not restored. To prevent this, set a shorter TTL when sending or callclearAllNotifications() on app launch. See Restored notifications (Android).
Can I access additionalData in the APNs root payload?
Yes. Enableadditional_data_is_root_payload via the Update an app API to place additionalData fields in the APNs root instead of inside the custom dictionary. See Move additionalData to APNs root for details.
Related pages
Android notification categories
Configure notification channels for Android 8.0+ devices.
Mobile Service Extensions
Add rich media, badges, and confirmed receipt tracking.
Mobile SDK reference
Full reference for OneSignal’s mobile SDK methods and listeners.
Deep linking
Route users to specific screens using launch URLs and custom data.