OSNotification payload

Details on the OneSignal notification payload details.

The OSNotification class provides the notification payload data accessible within the SDK notification event listeners.

Push notification payloads cannot exceed 4096 bytes of data. However, the limit is closer to roughly 3500 bytes due to our internal property names.

OSNotification class

The OSNotification class is composed of all getters. The class combines the original OSNotification with data previously on the OSNotificationPayload class into a single large OSNotification class.

TypeMethod/PropertyDescription
JSONObject
NSDictionary
getAdditionalData (Android)
additionalData (iOS)
Gets custom additional data that was sent with the notification. Set on the dashboard under Options > Additional Data or with the data field on the REST API. This field cannot exceed 2048 bytes.
intgetAndroidNotificationId (Android)Gets the unique Android Native API identifier.
String
NSString
getNotificationId (Android)
notificationId (iOS)
Gets the OneSignal notification UUID.
String
NSString
getBody (Android)
body (iOS)
Gets the body text of the notification.
NSStringsubtitle (iOS)Message Subtitle, iOS only.
String
NSString
getTitle (Android)
title (iOS)
Gets the title text of the notification.
String
NSString
getLaunchURL (Android)
launchURL (iOS)
Gets the URL opened when opening the notification.
StringgetLargeIcon (Android)Gets the large icon set on the notification.
String
NSDictionary
getBigPicture (Android)
attachments (iOS)
Gets the big picture image set on the notification.

iOS 10+ only. Attachments sent as part of the rich notification
StringgetSmallIcon (Android)Gets the small icon resource name set on the notification.
StringgetSmallIconAccentColor (Android)Gets the accent color shown around small notification icon on Android 5+ devices. ARGB format.
BackgroundImageLayoutgetBackgroundImageLayout (Android)If a background image was set, this object will be available.

The following methods on this object return strings:

- getBodyTextColor()
- getImage()
- getTitleTextColor()
StringgetLedColor (Android)Get LED string. Devices that have a notification LED will blink in this color. ARGB format.
StringgetCollapseId (Android)Gets the collapse id for the notfication.
List<ActionButton>
NSArray
getActionButtons (Android)
actionButtons (iOS)
The list of action buttons on the notification.

The following methods on this object return strings:

- getIcon()
- getId()
- getText()
intgetPriority (Android)The priority of the notification. Values range from -2 to 2 (see Android's NotificationCompat reference for more info.
StringgetFromProjectNumber (Android)Gets the Google project number the notification was sent under.
List<OSNotification>getGroupedNotifications (Android)Gets the notification payloads a summary notification was created from.
StringgetGroupKey (Android)Notifications with this same key will be grouped together as a single summary notification.
StringgetGroupMessage (Android)Gets the summary text displayed in the summary notification.
intgetLockScreenVisibility (Android)Privacy setting for how the notification should be shown on the lockscreen of Android 5+ devices.

1 (Default) - Public (fully visible)
0 - Private (Contents are hidden)
-1 - Secret (not shown).
StringgetSound (Android)Gets the sound resource played when the notification is shown. Read more here
String, NSStringgetTemplateId (Android)
templateId (iOS)
Unique Template Identifier from Templates.
String, NSStringgetTemplateName (Android)Name of Template from Templates.
OSMutableNotificationmutableCopy (Android)Extends OSNotification

Methods

- setAndroidNotificationId(int id)
- setExtender(Extender extender)
ExtendergetNotificationExtender (Android)
String
NSDictionary
getRawPayload (Android)
rawPayload (iOS)
Gets raw JSON payload string received from OneSignal.

Holds the raw APS payload received.
NSStringcategory (iOS)iOS Notification category key previously registered to display with.
NSStringthreadId (iOS)iOS 10+ only. Groups notifications into threads
BOOLcontentAvailable (iOS)True when the key content-available is set to 1 in the APNS payload. Used to wake your app when the payload is received.

See Apple's documenation for more details.
BOOLmutableContent (iOS)True when the key mutable-content is set to 1 in the APNS payload.

See Apple's documenation for more details.
NSIntegerbadge (iOS)The badge number assigned to the application icon.
NSIntegerbadgeIncrement (iOS)The amount to increment the badge icon number.
MethodparseWithApns (iOS)Parses an APS push payload into a OSNotificationPayload object. Useful to call from your NotificationServiceExtension when the didReceiveNotificationRequest:withContentHandler: method fires.

OSNotificationAction class

The action the user took on the notification.

TypeMethodDescription
String
NSString
getActionId() (Android)
actionID (iOS)
Notification button identifier
ActionTypegetType() (Android)
OSNotificationActionType (iOS)
The action type.

Enum:
0) Opened - notification was clicked

1. ActionTaken - button was clicked

OneSignal custom push payload

Each OneSignal SDK has a Notification Event Observer that gets triggered when a push is clicked or received.

On Android, our notification payload contains a "custom" key with a nested "i" value. If the notification payload received does not contain this, our SDK will not process the notification.

On iOS, we also have the same "custom" key with nested "i" value, however because Apple has a standard payload it will show all notification sent to the device. So if you send a push from your old platform to a device, do not send the same notification from OneSignal or the user will get it twice.

For iOS Click Handlers, depending on how you handle notification opens you might have to add a check for "custom": { "i": ""} as well. Or if you have your own format, we recommend checking for yours instead.


Adding notification data to iOS root payload

If you are needing to customize iOS payload, you can set your OneSignal app to include this custom data in the payload using our Update an app method and set additional_data_is_root_payload equal to true

Then any push you send with the data or Additional Data from the dashboard will be available in the APNS payload. For example:

... OneSignal Notification Data
"data": {
   "your-custom-data": "1"
} 

will result in the following sent to the device:

{
    "aps" : {
        "alert" : {
            "title" : "Notification Title",
            "body" : "Notification Body",
        }
    },
    "your-custom-data": "1"
}

Resulting in any additional code checking and handling this your-custom-data key at this location to work.

Additional payload properties

The payload can contain a restoring property which is not currently accessible. If you want to prevent a message from restoring, you should set a low or 0 TTL on your notifications. The OneSignal SDK omits restoring notifications if their TTL has expired.

NameTypeDetails
restoringbooleanTrue if the notification was restored after an app update, device reboot, and app opened after being force killed. If you have customized any alerting / priority settings check the restoring flag before applying them. You may want to omit displaying if your notification is no longer relevant to the user.