Maksim Morozov Maksim Morozov - 1 month ago 76
JSON Question

Read a title of OneSignal Notification in PhoneGap

I use PhoneGap Build and OneSignal.
How can I read a title of notification in PhoneGap Project.
There is my code

......
receivedEvent: function(id) {
var iosSettings = {};
iosSettings["kOSSettingsKeyAutoPrompt"] = true;
iosSettings["kOSSettingsKeyInAppLaunchURL"] = false;

window.plugins.OneSignal.startInit( "*************************", "************")
.handleNotificationReceived(didReceiveRemoteNotificationCallBack)
.handleNotificationOpened(didOpenRemoteNotificationCallBack)
.inFocusDisplaying(window.plugins.OneSignal.OSInFocusDisplayOption.None)
.iOSSettings(iosSettings)
.endInit();
}
};

function didReceiveRemoteNotificationCallBack(jsonData) {
alert('RECEIVE: ' + JSON.stringify(jsonData));
}
function didOpenRemoteNotificationCallBack (jsonData) {
alert('OPEN: ' + JSON.stringify(jsonData));
}

app.initialize();


How to get a TITLE when Notification receive?
I found a Documentations but I don't understand
https://documentation.onesignal.com/docs/phonegap-sdk#section-receiving-notifications

Answer

You can get it by calling jsonData.payload.title in your didReceiveRemoteNotificationCallBack function. See Onesignal's NotificationReceivedHandler documentation for a full list of properties.