How Posting One Signal Notification's Additional Data and Receiving That

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"]
}

How to send additional data in push notification with OneSignal API and PHP

Found it. :)

In $oneSignalConfig array (bottom of the code), i added following:

'key' => 'some value here',
'value' => 'something here',

Inside the function at $fields array, i added following:

'data' => array($oneSignalConfig['key'] => $oneSignalConfig['value'])

This did the trick. Key and Value is now sent with push notification.

How to add extra data OneSignal Push Notification?

You can send extra data as a map of data using the data parameter in their REST API. Refer to the following for more info:

https://documentation.onesignal.com/reference/create-notification#attachments

After sending the extra data, you can then get it using the relevant methods of OneSignal SDK.

one signal additional data in ionic 2/3

Here is how i redirect user to related page when app launch from notification.

app.component.ts

this.oneSignal.handleNotificationOpened().subscribe((data) => { 
let payload = data; // getting id and action in additionalData.
this.redirectToPage(payload);
});

redirectToPage(data) {
let type
try {
type = data.notification.payload.additionalData.type;
} catch (e) {
console.warn(e);
}
switch (type) {
case 'Followers': {
this.navController.push(UserProfilePage, { userId: data.notification.payload.additionalData.uid });
break;
} case 'comment': {
this.navController.push(CommentsPage, { id: data.notification.payload.additionalData.pid })
break;
}
}
}


Related Topics



Leave a reply



Submit