OSNotification Payload
The OSNotification Class provides the Notification Payload data accessible within the SDK Notification Event Handlers. This class require the Major Release Versions of the OneSignal SDK.
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. |
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.
Details on the OneSignal Notification Object and OneSignal Notification Payload.
On Android, our notification payload contains a “custom”
key with a nested “i”
value containing the OneSignal notification ID. 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": "notification_id"}
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.
Updated over 1 year ago