How posting One Signal notification's additional data and receiving that?
You set the data
field as a key in the dictionary passed to OneSignal.postNotification
like the following.
OneSignal.postNotification(["contents": ["en": "Test Message"],
"include_player_ids": ["3009e210-3166-11e5-bc1b-db44eb02b120"],
"data": ["postID": "id"]])
Then you need to get ready your keys from additionalData
from the payload
in the handleNotificationAction
function.
if let additionalData = payload?.additionalData {
let postID: String? = additionalData["postID"]
}
Example from iOS in objC to send additional data...
[OneSignal postNotification:@{@"contents":@{@"en":text},
@"include_player_ids":oneSignalIds,
@"data":@{@"key": @"value"},
}];
And to receive the data...
[OneSignal initWithLaunchOptions:launchOptions
appId:ONESIGNAL_APPID
handleNotificationReceived:^(OSNotification *notification) {
if (notification.payload.additionalData) {
NSDictionary* additionalData = notification.payload.additionalData;
if (additionalData[@"key"]){
NSLog(@"Received Data - %@", additionalData[@"key"]);
}
}
}
handleNotificationAction:nil
settings:@{kOSSettingsKeyInAppAlerts:@YES}];
Hope it helps someone :)