OneSignal / OneSignal-Xamarin-SDK

OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your Xamarin app with OneSignal. https://onesignal.com
Other
105 stars 50 forks source link

problem in IOS notification payload, Android manage correctly #215

Closed AngeloLazzari closed 4 years ago

AngeloLazzari commented 4 years ago

Description: Hi, I have all software stack and library update to the last version: Visual Studio and onesignal libraries. I have a xamarin form Android and Ios app, all is working perfectly on Android: when the notification is received the notification payload is parsed correctly, i mean, the JSON is correctly loaded into the payload variable with the code line:

        OSNotificationPayload payload = result.payload;

that is the first line of the function:

    private void HandleNotificationReceived(OSNotification result)

if you check out the visual studio inspector image here you can see the additionaData value having the correct value android

Problemas comes when the same notification is parsed from an iphone, so same project, same code, but different parsing into the "OSNotificationPayload payload" variable ... as you can see from the inspector image, the additionaData contains spaces and is not like the ANdroid versione.... ios

this problem cause an error of the app when I try to parse the JSON content...

It is a normal behaviour?

thank you very much

AngeloLazzari commented 4 years ago

here is a pastebin of the VERBOSE log since start of the app, and crash of it due to the error parsing the returned payload.

https://pastebin.com/XjNnuSUV

thank you very much

rgomezp commented 4 years ago

Howdy, Take a look at our docs here.

You may be missing the body parameter.

// Called when your app is in focus and a notificaiton is recieved.
// The name of the method can be anything as long as the signature matches.
// Method must be static or this object should be marked as DontDestroyOnLoad
private static void HandleNotificationReceived(OSNotification notification) {
  OSNotificationPayload payload = notification.payload;
  string message = payload.body;

  print("GameControllerExample:HandleNotificationReceived: " + message);
  print("displayType: " + notification.displayType);
  extraMessage = "Notification received with text: " + message;
}

Hope that helps.

AngeloLazzari commented 4 years ago

Hi @rgomezp thank you for you reply, really apreciated. the body property does not work for us because we need to take the payload.additionalData and on it get the noticationType = additionalData["type"].ToString(); notificationData = additionalData["data"].ToString(); to perform our app logic.

the problem totally there, I mean, for IOS the payload additionalData has a JSON WRONG like in the this image: Captura de pantalla 2020-09-02 a las 10 12 04

and on Android, SAME CODE in app and backend, the payload comes CORRECTLY like this other image: Captura de pantalla 2020-09-02 a las 10 21 59

So, parsing like JSON the IOS goes into a parsing error.

I checked the oneSignal messages for both projects and the sent messages are the same.

thank you very much! Angelo

AngeloLazzari commented 4 years ago

Hi, please, I need on this, I tried to get rid of it but no way.... , thank you very much Angelo

AngeloLazzari commented 4 years ago

Hi, we found a workaround to fix it: In the ONE SIGNAL API call from out backend, just added a \ before every " present into the JSON we sent into the additionaldata field, doing this, IOS now is working correctly, as Android did before, without the workaround.

So, before we sent: {"type":"keepalive","data":{"customerCode":"aaa","readerCode":"1","timestamp":"2020-09-02 08:21:48","online":true}}

and now we send {"type":"keepalive","data":"{\"customerCode\":\"aaa\",\"readerCode\":\"1\",\"timestamp\":\"2020-09-02 08:21:48\",\"online\":true}"}

I still think this should be fixed on the OneSignal Xamarin SDK, i mean, the two platform should work the same way.... no?

thank you very much Angelo

rgomezp commented 4 years ago

Howdy, I'm glad you were able to resolve! We will look into whether we can implement a permanent solution. This will be tracked internally.

Enjoy!