Hello everyone. I'm having issues trying to find out how to work with custom data being sent from the Apple Notification Service. My app is subscribed to receive push notifications from APNs. In my AppDelegate in the iOS app, I am calling RegisteredForRemoteNotifications in the FinishedLaunching method. I am successfully subscribed and I can send notifications to my app through APNs. They show up on my device as they should. I wanted to send custom data to the app when I send a notification. The custom data is outside of the 'aps' JSON class (as it should be) and it comes through to the app.
In the app, I have a custom delegate that I attach to the iOS user notification center. This allows the overrides WillPresentNotification method in my delegate to fire. Here is the structure of that method...
WillPresentNotification(UNUserNotificationCenter center, UNNotification notification, Action<UNNotificationPresentationOptions> completionHandler)
The problem is that when I receive the data, it doesn't come back as properly formatted JSON that I am clearly sending from the server side. When I look at the custom data that comes back in the notification.Request.Content.UserInfo["jobject_name"].ToString(); property, it has no colons or quotes and is not properly JSON formatted. On the server side that sends the push notification, I am creating valid JSON data using Newtonsoft JObject's and attaching data to the notifications. It's the same process that I am using to build the aps class for the notification itself. I can see the data is properly formatted before I submit it to APNs. The data is coming from custom classes in my library. I have functions that convert my custom classes to and from JObject's (JSON). they work great, but since APNs is removing the JSON formatting, it fails to convert it back to my custom objects on the app side, because of invalid JSON data.
The ultimate goal is to translate the custom data received from APNs back into my custom class within the app. I think the UserInfo property of the notification is NSData. My research hasn't turned up any results for finding out why the data coming from APNs isn't properly formatted JSON or how to convert the NSData back to valid JSON. If they expect us to send them properly formatted JSON, then why do they give us invalid JSON when we receive it?? Maybe I'm not extracting the data in the proper way or from the proper area? Maybe what I am looking at is just raw data when I call ToString(). I'm new to iOS and Xamarin development, so any hints on where/how to look would be greatly appreciated. Thank you in advance.