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
OSNotification
classThe 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.
Type | Method/Property | Description |
---|---|---|
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. |
int | getAndroidNotificationId (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. |
NSString | subtitle (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. |
String | getLargeIcon (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 |
String | getSmallIcon (Android) | Gets the small icon resource name set on the notification. |
String | getSmallIconAccentColor (Android) | Gets the accent color shown around small notification icon on Android 5+ devices. ARGB format. |
BackgroundImageLayout | getBackgroundImageLayout (Android) | If a background image was set, this object will be available. The following methods on this object return strings: - getBodyTextColor() - getImage() - getTitleTextColor() |
String | getLedColor (Android) | Get LED string. Devices that have a notification LED will blink in this color. ARGB format. |
String | getCollapseId (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() |
int | getPriority (Android) | The priority of the notification. Values range from -2 to 2 (see Android's NotificationCompat reference for more info. |
String | getFromProjectNumber (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. |
String | getGroupKey (Android) | Notifications with this same key will be grouped together as a single summary notification. |
String | getGroupMessage (Android) | Gets the summary text displayed in the summary notification. |
int | getLockScreenVisibility (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). |
String | getSound (Android) | Gets the sound resource played when the notification is shown. Read more here |
String , NSString | getTemplateId (Android)templateId (iOS) | Unique Template Identifier from Templates. |
String , NSString | getTemplateName (Android) | Name of Template from Templates. |
OSMutableNotification | mutableCopy (Android) | Extends OSNotification Methods - setAndroidNotificationId(int id) - setExtender(Extender extender) |
Extender | getNotificationExtender (Android) | |
String NSDictionary | getRawPayload (Android)rawPayload (iOS) | Gets raw JSON payload string received from OneSignal. Holds the raw APS payload received. |
NSString | category (iOS) | iOS Notification category key previously registered to display with. |
NSString | threadId (iOS) | iOS 10+ only. Groups notifications into threads |
BOOL | contentAvailable (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. |
BOOL | mutableContent (iOS) | True when the key mutable-content is set to 1 in the APNS payload. See Apple's documenation for more details. |
NSInteger | badge (iOS) | The badge number assigned to the application icon. |
NSInteger | badgeIncrement (iOS) | The amount to increment the badge icon number. |
Method | parseWithApns (iOS) | Parses an APS push payload into a OSNotificationPayload object. Useful to call from your NotificationServiceExtension when the didReceiveNotificationRequest:withContentHandler: method fires. |
OSNotificationAction
class
OSNotificationAction
classThe action the user took on the notification.
Type | Method | Description |
---|---|---|
String NSString | getActionId() (Android)actionID (iOS) | Notification button identifier |
ActionType | getType() (Android)OSNotificationActionType (iOS) | The action type. Enum: 0) Opened - notification was clicked1. 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.
Name | Type | Details |
---|---|---|
restoring | boolean | True 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. |
Updated about 1 month ago