25
Views
1
Comments
[OneSignal Plugin] In OneSignal plugin, I am unable to fetch Notification Id from notification data
onesignal-plugin
Mobile icon
Forge asset by OutSystems
Application Type
Mobile

Hello,

I am using this plugin for both iOS and android. Notification received and opened events are working fine in android and ios but in ios, I am getting below response using which I am unable to get Notification Id.


iOS -  {"notification":{"shown":true,"displayType":1,"payload":{"title":"IOS","body":"IOS TEST","sound":"default","rawPayload":"[object Object]","Deeplink":{"Parameters":[]}},"groupedNotifications":[]},"action":{}}


Android :  

{"body":"Test1","lockScreenVisibility":1,"fromProjectNumber":"xxxxxxxx","rawPayload":"{\"google.delivered_priority\":\"normal\",\"google.sent_time\":1669728975916,\"google.ttl\":259200,\"google.original_priority\":\"normal\",\"custom\":\"{\\\"a\\\":{},\\\"i\\\":\\\"xxxxxxxxx\\\"}\",\"pri\":\"5\",\"vis\":\"1\",\"from\":\"xxxxx\",\"alert\":\"Test1\",\"google.message_id\":\"0:1669728975950501%869fbfbdf9fd7ecd\",\"google.c.sender.id\":\"xxxxx\",\"androidNotificationId\":304362882}","Deeplink":{"Parameters":[]}} 

rawPayload is a text, holding "[object Object]" (only in iOS) which I cannot convert to array object.


If I use OneSignal cordova plugin, I am able to get Notification id but, notification open event is not working when the app is opened.


window.plugins.OneSignal  .startInit($parameters.AppId)  .handleNotificationReceived(function(notificationData) {    console.log('Notification Received: ' + JSON.stringify(notificationData));    if($parameters.isIOS)        $actions.OnNotificationReceivediOS(JSON.stringify(notificationData));    else        $actions.OnNotificationReceivedAndroid(JSON.stringify(notificationData));  })  .endInit();


  window.plugins.OneSignal  .startInit($parameters.AppId)  .handleNotificationOpened(function(openResult) {    console.log('Notification opened: ' + JSON.stringify(openResult));        if($parameters.isIOS)        $actions.OnNotificationOpenediOS(JSON.stringify(openResult));    else       $actions.OnNotificationOpenedAndroid(JSON.stringify(openResult));  })  .endInit();

2023-08-01 16-31-38
Nagaraju Gaddam

I created notification open and received events along with structures by using cordova plugins.

Now, I can get notification id and all other required data from the response. Thank you!

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.