question

info-9 avatar image
info-9 asked

SendPushNotification package property not behaving as expected

I tried out the new package property of server.SendPushNotification that was currently introduced with Playfab SDK 170710 and was glad to have more control now over the push notification. However it doesnt seem to do what it should.

The push message text that I receive on my iPhone is not the string that I fill into "request.package.message" but instead it is the whole json-formatted string of the package, with all the brackets.

I tried it in two different ways (and the api call result of both ways says successful):

The first way is via the "Try it" button on the API docu page. In the "Package: (Optional)"-field I fill

{  "Title" : "mytesttitle",  "Message": "mytestmessage"}

The second way is via cloudscript. I use this cloudscript:

handlers.SendPushNoteTest = function (args)
{
      var request = {
        Recipient: "EA1BC04E11E45371", 
        Package: {
                Title: "mytesttitle",
                Message: "mytestmessage"
            }
    };
    server.SendPushNotification(request);
}

Doing that I expect a push note on my iPhone with the message

mytestmessage

Instead I receive (in both cases) a push message saying

{"ScheduleDate":null,"Title":"mytesttitle","Message":"mytestmessage","Icon":null,"Sound":null,"CustomData":null}

So the whole json-string is displayed instead of only the message.

10 |1200

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

brendan avatar image
brendan answered

The Package is for defining the JSON package for an advanced Push Notification - something we provide a plugin for on Android, but not iOS. I've opened a bug to have that clarified in the docs. We will be providing a plugin for iOS later, but in the near-term, we'll also be providing an optional parameter in SendPushNotification that specifies if the message should only be sent to specific device types.

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

larissa avatar image larissa commented ·

Hey! I've been asking a similar question (https://community.playfab.com/questions/13165/using-the-package-parameter-of-sendpushnotificatio.html) and was referred to this post. While this partially answers my questions, I don't see how this is only an issue with the docs or a missing iOS plugin:

1.) The push notification payload that playfab is building simply does not seem to adhere to the formats that the apple push notification service and the Google Cloud Messaging service require. Both services provide designated fields for custom data, for title and for message that should be used.

2.) Even with an iOS plugin I don't see how above json-string could be prevented from being displayed to the user? If the notification is received while the application is not running there simply is no way to intercept it before being shown. Or am I missing anything here?

0 Likes 0 ·
brendan avatar image brendan larissa commented ·

Correct, it's specifically because the Push Notifications aren't using those fields. Our engineering team is having a look at updating the Push service to make use of the various platform specifics, rather than our plugin model.

0 Likes 0 ·
zacho avatar image zacho commented ·

Do you have an estimate on when the extra parameter for SendPushNotification will be available?

0 Likes 0 ·
brendan avatar image brendan zacho commented ·

Not currently, sorry. Our tools team is also working with the engineering team on a broader update to the Push Notifications, however. The intent is to move away from the need for a plugin for advanced Push functionality (and only allowing for the features the platforms support directly).

0 Likes 0 ·
zacho avatar image zacho brendan commented ·

Do you have any suggestions for how to proceed with the current implementation? I would like to comply with Android style guidelines to use an alpha only image as the icon for push notifications (and if we use the default app icon it becomes a white square), but anything I think I can do either gets the json string for iOS or the wrong icon for Android.

0 Likes 0 ·
Show more comments
info-9 avatar image
info-9 answered

@larissa

as far as I understand it:

to your 2.) question: I think it would be possible to display the message instead of the json string even if the application is not running, because it doesnt work that way, that the push notification is received by the application which then formats and displays it. IOS does the displaying on its own once your application has registered for push. And it just displays messages according to how you pass the json dictionary to the Apple APNS.

So APNS expects a json dictionary formatted like this:

    {
        "aps" : 
        { 
          "alert" : "displayedMessageText",
          "badge" : 9, //optional
          "sound" : "bingbong.aiff" //optional
        }
    }

or if you specify the alert field then like this

    {
        "aps" : 
        { 
          "alert" : 
          {
            "title" : "Game Request",
            "body" : "displayedMessageText"
          },
          "badge" : 9, //optional
          "sound" : "bingbong.aiff" //optional
        }
    }

So what Playfab does is using the string that we pass into the SendPushNotification.Message field and constructs a json dictionary like above with filling our supplied message string in either the "aps.alert" field or the "aps.alert.body" field and then sends this json to APNS who takes care of displaying it as notification on the user device.

So a great way (which didn't even need any iOS plugin) would be if we could not only specify a message string (which Playfab passes on to APNS.aps.alert) but instead if we could define a json object, which Playfab passes on to APNS.aps (so to just one level higher). This would highly improve Playfabs iOS push feature since then all features that APNS offers would just be handed on to us.

Is this worth a feature request?

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.

brendan avatar image brendan commented ·

I would normally say yes, but our engineering team has already been discussing an update to use the Apple/Google defined formats, so I believe we'll be making a change to support this soon.

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.