I am trying to send a notification via Cloud Script for an iOS app. Notifications are configured, "SendPushNotificationFromTemplate" works as expected, but in some cases I need to replace the text inside the message. You cannot add parameters to Template notifications.
If I specify only the "Message" field in the request, the notification will come without a header and without sound. I tried using the "Package" field, but on iOS the notification comes with no sound and no header, and there is a huge JSON in the message instead of text.
I realized that I needed to use "AdvancedPlatformDelivery", but dozens of my attempts ended up with an error log, and I can't figure out what I was doing wrong
The log looks like this:
i'm "iOS Push Notification Failed: ValidationError 1 validation error detected: Value null at 'message' failed to satisfy constraint: Member must not be null",
If I add an additional field to the request, for example "Message", no matter with what content, I get another error log:
"Only one of the following properties can be defined: Message, Package, AdvancedPlatformDelivery"
I need to send a notification with title, text, and so that it comes with sound on iOS via a cloud script. I have already looked through many similar topics, but for some reason none of the solutions worked for me ... I can't find the cause of the problem for more than a day... Here is my Cloud script:
handlers.SendCustomPushNotification = function (args, context){
let TargetUserID = args.targetUserID;
let Title = args.title; let Message = args.message; var IOSPayload = { "alert" : { "title" : Title, "body" : Message }, "badge" : 1, "sound" : "default" }; server.SendPushNotification( { Recipient: TargetUserID, AdvancedPlatformDelivery: [ { Platform:"ApplePushNotificationService", Json: JSON.stringify(IOSPayload) } ], TargetPlatforms: [ "ApplePushNotificationService" ] });
}
And log
"Message": "PlayFab API request error", "Level": "Error", "Data": { "api": "/Server/SendPushNotification", "request": { "Recipient": "88DF2E5369B3F3C0", "AdvancedPlatformDelivery": [ { "Platform": "ApplePushNotificationService", "Json": "{\"alert\":{\"title\":\"Testing title\",\"body\":\"Testing message\"},\"badge\":1,\"sound\":\"default\"}" } ], "TargetPlatforms": [ "ApplePushNotificationService" ] }, "result": null, "apiError": { "code": 400, "status": "BadRequest", "error": "PushServiceError", "errorCode": 1095, "errorMessage": "iOS Push Notification Failed: ValidationError 1 validation error detected: Value null at 'message' failed to satisfy constraint: Member must not be null", "errorHash": null, "errorDetails": null } }
I tried additionally specifying AdvancedPlatformDelivery for Android, but was getting exactly the same error...
What am I doing wrong?