question

Joris avatar image
Joris asked

Wrong iOS custom payload with advanced notifications API

I've been working on custom payloads in notifications to support deep linking from push notifications. I was using an "advanced" notification template for easy testing. Once I got all the deep linking working with the app, I figured I would quickly add the code in a cloud script... Unfortunately, the AdvancedPlatformDelivery behaves differently than the advanced notification templates! The same issue was reported here: https://community.playfab.com/questions/28199/getting-custom-data-from-push-notifications-via-re.html

Basically, the following advanced notification iOS payload works great with advanced notification template:

{ "aps": { "alert": { "title": "Bob invited you to a game!", "body": "invitation to play" }, "sound": "default" }, "data": { "deepLink": "some deep link" } }

Notice that, as per requirements for iOS, my custom "data" field I added is outside the "aps" node. This JSON works great in advanced templates. Now, using SendPushNotification with AdvancedPushPlatformMsg with the "Json" set to the exact same JSON, the following shows up in the sent_push_notification telemetry:

"aps": { "aps": { "alert": { "title": "Bob invited you to a game!", "body": "invitation to play" }, "sound": "default" }, "data": { "deepLink": "some deep link" } } }

Clearly this is invalid - and indeed the push notification never arrives on my phone. The API seems to be wrapping my whole advanced JSON inside a hard-coded "aps" node. I can make the notification work by just sending the contents inside MY aps node (I confirmed that sends a notification), but that means I cannot send my custom "data" node, which is the whole purpose of using advanced.

I realize that fixing this is a breaking change. But at this point, it's impossible to send custom payload data to iOS. Perhaps a new API or a new optional field to the advanced notifications API request would unblock this scenario? Perhaps a flag to indicate that aps is included in the JSON and doesn't have to be added by the API?

I can't use templates because there is no way to pass in parameters to customize the message, is there?

Push Notifications
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Xiao Zha avatar image
Xiao Zha answered

Update:You may also try the workaround in this post: iOS push notification payload cloudscript - Playfab Community

PlayFab SendPushNotification API doesn’t support to send custom data with “AdvancedPushPlatformMsg” parameter, you can only write children of “aps” node. You can post a feature request for it.

And the SendPushNitificationFromTemplate API doesn’t have the message parameter, so, you cannot send customize messages with it. The workaround here is to create multiple templates with different messages, and call SendPushNitificationFromTemplate with different TemplateIds.

4 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Joris avatar image Joris commented ·

It's not a feature request, it's a bug report :-)

The API also has a "Package" field of type "PushNotificationPackage". This actually has a field named "CustomData". Unfortunately, it's contents ALSO gets put inside the aps node...

0 Likes 0 ·
Xiao Zha avatar image Xiao Zha Joris commented ·

As @JayZuo said in this post: iOS Push Notification CustomData is Empty - Playfab Community, PlayFab only supports aps key for iOS Push Notification. Custom keys and values are not supported. You may vote for this feature request: Push notifications for IOS support for custom data - Playfab Community.

0 Likes 0 ·
Joris avatar image Joris commented ·

I'm using the category field right now which works, so I guess that's similar to the workaround in the post you linked.

0 Likes 0 ·
Xiao Zha avatar image Xiao Zha Joris commented ·

Glad to hear your workaround worked.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.