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
How to Convert an Int into Nsdata in Swift
Changing the Shape of a Uiview Border
Adding Uigesturerecognizer to Subview Programmatically in Swift
How to Make a Popup Window with an Image Swift
Using Cloud Code with the Parse Server and Heroku
In Collectionview How to Set Colors According to Selection
Show Bounding Box While Detecting Object Using Arkit 2
iOS Swift3 Check Nil Value for Viewcontroller Object
Design Pattern for Realm Database Swift 3.1 - Singleton
Endless Scrolling (Repeating) Background in Spritekit Game - Swift
How to Enable Only Numeric Digit Keyboard iOS Swift
How to Get All the Sundays in Array of Date iOS
Swift 3 - How to Improve Image Quality for Tesseract
How to Run My Performance Tests More Than Ten Times
Periodically Call an API with Rxswift
Locationmanager Didupdatelocations Fires Twice on Device, Only Once on Simulator
Changing Font Size in a Label for Only iPhone 4S, Is This Possible