question

Kim Strasser avatar image
Kim Strasser asked

How can I use AdvancedPlatformDelivery to send push notifications?

I don't understand how to use AdvancedPlatformDelivery-Version to send push notifications to a registered iOS/Android device. I want to send a message with the Title: "Welcome message" and the message body "Hello "+ displayname of the Player. How can I do that?

Can I use one cloud script version for Android and iOS or is it necessary to create two different cloud scripts(one for iOS and one for Android)?

My cloud script:

handlers.Welcome = function (args, context)
{
    try
    {
    jsonObjectIOS =
    {
	"customData" : customDataString, // include any additional data here
	"content-available": 1
    };
 
    let jsonStringIOS = JSON.stringify(jsonObjectIOS);
 
    let plattformIOS = "ApplePushNotificationService";
 
    let pushNotificationResult = server.SendPushNotification
    ({
	    Recipient: recipientPlayFabId,
        AdvancedPlatformDelivery:
        [
            {
                Json: jsonStringAndroid,
                Platform: plattformAndroid
            },
            {
        	    Json: jsonString,
                Platform: plattformIOS
            }
        ]
    });
        server.SendPushNotification({ Package : { Message : "Hello", Title: "Welcome message" }});
   }
   catch (ex)
   {
        // Target player has not registered for Push Notifications
   }
}

client application code:

string Errormsg = "";

private async Task SendPushNotification()
{
  var result = await PlayFabClientAPI.ExecuteCloudScriptAsync(new ExecuteCloudScriptRequest()
  {
    FunctionName = "Welcome",
    GeneratePlayStreamEvent = true
  });

  if (result.Error != null)
    Errormsg = result.Error.Error.ToString();
  else
    Errormsg = "Sending Push notification successful?";
}
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

·
Seth Du avatar image
Seth Du answered

We are still working on the documentation on AdvancedPlatformDelivery but I cannot tell the ETA and still, feel free to post a Feature Requests thread on corresponding forum.

Hence, we suggest you to use the Push Notification Template Feature. You may find push notification template at [Game Manager] ->[Content]. It can handle not only different platforms but also multiple languages. However recently we are experiencing unknown issues with Push Notification Template and I will keep you informed if there is any fix or updates.

Have you tried to send notification via AdvancedPlatformDelivery? If it is Android, according my experience of testing, the data sent via this method will not automatically pop up a notification, but you are able to receive all the data in onReceive method. You may manually craft an notification in the client.

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.

Kim Strasser avatar image Kim Strasser commented ·

I don't know how to use AdvancedPlatformDelivery. For example, I don't know how to create the client application code to call the cloud script. I will wait on the documentation. In the meanwhile, I use the Package-Version of SendPushNotification: https://community.playfab.com/questions/31757/i-dont-receive-my-cloud-push-notifications.html

In addition, I will try the template feature because I need push notifications in different languages.

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.