8

I read the doc here : https://documentation.onesignal.com/docs/cordova-sdk but it's totally not clear !

I try severals test nothing, I event test to get the title but still nothing

document.addEventListener('deviceready', function () {
  // Enable to debug issues.
  // window.plugins.OneSignal.setLogLevel({logLevel: 4, visualLevel: 4});

  var notificationOpenedCallback = function(jsonData) {
    alert('notificationCallback: ' + JSON.stringify(jsonData)); => json data

        alert('Title : '+ JSON.stringify(jsonData.payload.title)); => nothing

        alert('Title2 : '+ jsonData.payload.title); => nothing


        alert('Additional data: '+ jsonData.payload.additionalData); => nothing
    };


  window.plugins.OneSignal
    .startInit("MY_ID")
    .handleNotificationOpened(notificationOpenedCallback)
    .endInit();
}, false);

How to retrieve this data..

Thanks

Jean R.
  • 476
  • 4
  • 16
  • 44

2 Answers2

3

After multiple debugs on my app, I finally found the application. The JSON structure of jsonData is :

jsonData
    notification: {
        payload: {
            title: "YOUR_TITLE",
            body: "BODY",
            additionalData: {
                "YOUR_KEY" : "YOUR_VALUE"
            },

So to retrieve your data :

JSON.stringify(jsonData.notification.payload.additionalData.<YOUR_KEY>)
Jean R.
  • 476
  • 4
  • 16
  • 44
0

Instead of jsonData.payload try with jsonData.OSNotificationPayload

Ex: to access title

jsonData.OSNotificationPayload.title
Vibin TV
  • 822
  • 9
  • 28
  • Hi, thanks for the reply. But it still doesn't work. No alerts : `alert('notificationCallback: ' + JSON.stringify(jsonData)); => //all data alert('Payload: ' + JSON.stringify(jsonData.OSNotificationPayload)); // => undefined alert('Title : '+ JSON.stringify(jsonData.OSNotificationPayload.title)); // => no alerts alert('Data : '+ JSON.stringify(jsonData.OSNotificationPayload.additionalData)); // => no alerts` – Jean R. Mar 28 '18 at 09:50