question

Linda Shi avatar image
Linda Shi asked

iOS push notification payload cloudscript

Soo....the payload for notification on the push notification doesn't work, therefore I've been trying to setup push notification with via cloudscript, it works fine with android using Package -> CustomData, but doesn't seem to work at all for iOS.

The push notification delivers fine, just not the payload.

I also tried using AdvancedPlatformDelivery, which gave an error:

handlers.GlobalSendNotification = function (args) {
    return GlobalSendNotification_internal(args.title,args.message,args.payload);
}


function GlobalSendNotification_internal(title, message, payload) {
    server.SendPushNotification({
        Recipient: currentPlayerId, 
	Package: { Message: message, Title: title, Badge: 0, CustomData: payload },
        AdvancedPlatformDelivery:
            [
                {
                    Json: payload,
                    Platform: "ApplePushNotificationService"
                }
            ]});
}

and it gave an error:

{
    "FunctionResult": null,
    "Logs": [
        {
            "Level": "Error",
            "Message": "PlayFab API request error",
            "Data": [
                [
                    []
                ],
                [
                    [
                        [
                            []
                        ],
                        [
                            [
                                [
                                    []
                                ],
                                [
                                    []
                                ],
                                [
                                    []
                                ],
                                [
                                    []
                                ]
                            ]
                        ],
                        [
                            [
                                [
                                    [
                                        []
                                    ],
                                    [
                                        []
                                    ]
                                ]
                            ]
                        ]
                    ]
                ],
                [
                    []
                ],
                [
                    [
                        [
                            []
                        ],
                        [
                            []
                        ],
                        [
                            []
                        ],
                        [
                            []
                        ],
                        [
                            []
                        ],
                        [
                            []
                        ],
                        [
                            [
                                [
                                    [
                                        []
                                    ]
                                ]
                            ]
                        ]
                    ]
                ]
            ]
        }
    ],
    "ExecutionTimeSeconds": 0.0053336,
    "MemoryConsumedBytes": 19280,
    "APIRequestsIssued": 1,
    "HttpRequestsIssued": 0,
    "Error": {
        "Error": "CloudScriptAPIRequestError",
        "Message": "The script called a PlayFab API, which returned an error. See the Error logs for details.",
        "StackTrace": "Error\n    at Object.server_request (Script:180:24)\n    at Object.server.SendPushNotification (Script:597:77)\n    at GlobalSendNotification_internal (91E7F-main.js:7872:12)\n    at handlers.GlobalSendNotification (91E7F-main.js:7868:12)\n    at Object.invokeFunction (Script:116:33)"
    }
}

What is the correct way of sending push notification with payload for ios?

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.

Tim Koppers avatar image
Tim Koppers answered

I've cheated by using a json string as value for 'action-loc-key'. That's a dirty solution that works....

1 comment
10 |1200

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

Linda Shi avatar image Linda Shi commented ·

Thank you!! I will try that!

0 Likes 0 ·
JayZuo avatar image
JayZuo answered

May I know what's the iOS payload you want to send? As the help page under Push Notification Templates (clicking “What's this?” when creating or editing Push Notification Template) said:

The iOS payload consists of one key-value pair, "aps". The "aps" key-value should contain a dictionary with key-value pairs as detailed in the Payload Key Reference under the heading "APS Dictionary Keys".

Thus, there is no "CustomData" support for iOS. it works for Android as Android payload consists of two key-value pairs, "notification" and "data". "CustomData" will be put into Android's "data" filed.

For iOS, if you want to use any keys that can't be set with "Package", then I'd suggest using "AdvancedPlatformDelivery" only. For example:

{
    "Recipient": "{
                {PlayFabId}}",
    "AdvancedPlatformDelivery": [
        {
            "Platform": "ApplePushNotificationService",
            "Json": "{\"alert\":{\"title\":\"Game Request\",\"body\":\"Bob wants to play poker\",\"action-loc-key\":\"PLAY\"},\"badge\":5}"
        }
    ],
    "TargetPlatforms": [
        "ApplePushNotificationService"
    ]
}

3 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.

Linda Shi avatar image Linda Shi commented ·

The ios payload i wanted includes some actions:

{"title":"test", "message":"here's some items!", "payload":"{\"grantedItems\":[{\"id\":\"item1\", \"amount\":5},{\"id\":\"item2\",\"amount\":5}], \"targetUI\":\"shop\",\"targetItem\":\"shop\"}"}

so the aps dictionary is not going work :\

is there anyway to pass in the dictionary one layer above aps dict?

for example this:

0 Likes 0 ·
JayZuo avatar image JayZuo ♦ Linda Shi commented ·

Unfortunately, PlayFab Push Notification only supports "aps" key-value pair for iOS payload. Please feel free to submit a feature request if you want to add custom keys and values for Apple Push Notification Service.

0 Likes 0 ·
Linda Shi avatar image Linda Shi commented ·

can't seem to post image in comments:

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.