question

bda2206@gmail.com avatar image
bda2206@gmail.com asked

IOS Push not received in application

Hi,

I've updated to FCM in my project, and added a new apple pem file.

When I register for push, I request a confirmation message, which comes through to the application OK, it shows in my debug logs etc..

After that, all the messages go to the device but are not intercepted by the application.

I've tried with cloudscript, and also the "try it" in the documentation.

whats the difference in the messages being sent?

my project ID is 65D6

tia,

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 answered

@bda2206@gmail.com Not sure if it helps, but silent notifications can be achieved, if you use the AdvancedPlatformDelivery-Version instead of Package-Version of SendPushNotification

The following is a Cloudscript Helper function I used to do it:

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: jsonStringIOS,
                Platform: plattformIOS
        }
	]
});

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

bda2206@gmail.com avatar image bda2206@gmail.com commented ·

oh my god! you're awesome.

0 Likes 0 ·
brendan avatar image brendan commented ·

An excellent point - the AdvancedPlatformDelivery option is also available, if that'll work for you:

https://api.playfab.com/documentation/Server/datatype/PlayFab.Server.Models/PlayFab.Server.Models.AdvancedPushPlatformMsg

0 Likes 0 ·
bda2206@gmail.com avatar image bda2206@gmail.com brendan commented ·

thanks also for your time & effort here brendan, it is appreciated.

Am I right that this message would only go to IOS, and if I wanted to send to android, I'd have to send another message?

0 Likes 0 ·
larissa avatar image larissa bda2206@gmail.com commented ·

It only goes to IOS, however you can directly include a notification for android devices with the same request

let pushNotificationResult = server.SendPushNotification
            ({
                Recipient: recipientPlayFabId,
                AdvancedPlatformDelivery: [
                {
                    Json: jsonStringAndroid,
                    Platform: plattformAndroid

                },
                {
                    Json: jsonStringIOS,
                    Platform: plattformIOS
                }
            ]
            });


2 Likes 2 ·
Show more comments
orhanozsoy avatar image orhanozsoy commented ·

How can i acces this customData on client? when player receive a message.

0 Likes 0 ·
larissa avatar image larissa orhanozsoy commented ·

Depends on the client:

For Android you can extend FirebaseMessagingService and override onMessageReceived. There you can extract your customData from remoteMessage.getData().

On iOS you can use application:didReceiveRemoteNotification:fetchCompletionHandler

The format in which you'll receive the data might vary depending on which parameters you are using in your SendPushNotification call and how you included your customData.

There may or may not be an easier way if you're using Unity, which I'm not familiar with.

0 Likes 0 ·
orhanozsoy avatar image orhanozsoy larissa commented ·

jsonObject ={ "customData" : {"senderName":name}, "content-available": 1 }; my json object like this. i used stringify code and convert string then added in delivery object. By the way I am using Unity and onMessageReceived returns a message parameter, but this parameter's data null, raw data null, and there is no option remoteMessage.getData or something like that.I can only take body, title or like this parameter. Thank you for answering,i have a one more question to you. I used this code because i want silent push on android do you know other ways but more easier ways for make this? Am i on wrong way for to do this?

0 Likes 0 ·
Show more comments
brendan avatar image
brendan answered

If you've added FCM to your Unity project, please see this thread for more info: https://community.playfab.com/questions/15918/fcm-ios-push-notifications-arent-working-android-d.html. Long story short, the FCM plugin causes compatibility issues.

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

bda2206@gmail.com avatar image bda2206@gmail.com commented ·

Hi Brendan,

I'm using xamarin not unity. I've tried creating a new project without upgrading to FCM but still the same symptom.

When I register for push, I request a confirmation message, which comes through to the application OK, it shows in my debug logs etc..

After that, all the messages go to the device but are not intercepted by the application.

I've tried with the app in foreground and background.. I don't think its your playfab end with the problem at this point.

regards

0 Likes 0 ·
brendan avatar image brendan bda2206@gmail.com commented ·

No, I'm sure it's not. The SendPushNotification call sends a push via AWS SNS, in the native format for the device in question. The problem we've seen with FCM is that their plugin intercepts the message and expects a format which isn't native to the platform, which effectively blocks messages. Is it possible for you to do a test pass without FCM, to see what your results are?

0 Likes 0 ·
bda2206@gmail.com avatar image bda2206@gmail.com brendan commented ·

I created title 49BE and did not upgrade it to FCM. Recompiled app against new title and got the same result. Is that what you mean?

The application is not using the FCM version of the push plugin. I use this one

https://github.com/CrossGeeks/PushNotificationPlugin

not this one

https://github.com/CrossGeeks/FirebasePushNotificationPlugin

0 Likes 0 ·
Show more comments
bda2206@gmail.com avatar image bda2206@gmail.com commented ·

Hi @Brendan,

I've been told this..

On iOS by default notification is received once you tap the notification not before.

On iOS to get a silent notification you should send "content_available" : 1 inside the "aps" payload key.

I need to pass in {"aps":{"content-available":1}} for the push message to go directly to the application, otherwise it goes to the application if you tap the toast...

not sure how to achieve that. I tried a package like this

{"badge" : 1, "customdata" : {"aps":{"content-available":1} }, "Message" : "the message", "Title" : "the title"}

{
 "code": 400,
 "status": "BadRequest",
 "error": "InvalidParams",
 "errorCode": 1000,
 "errorMessage": "Invalid input parameters",
 "errorDetails": {
  "Title": [
   "The Title field is required."
  ],
  "Message": [
   "The Message field is required."
  ]
 },
 "CallBackTimeMS": 1152
}

thanks for any insight..

0 Likes 0 ·
brendan avatar image brendan bda2206@gmail.com commented ·

Have a look at this tutorial - it has an example of using Package: https://api.playfab.com/docs/tutorials/landing-players/push-notification-basics.

Also, bear in mind that while Package is an Object, CustomData is a String, so it needs to be a stringified JSON. So in this case, given your parameters, yours would look like this:

Package : {
    Badge: 1,
    Message : "the message",
    Title: "the title",
    CustomData: "{\"aps\":{\"content-available\":1} }"
}
0 Likes 0 ·
bda2206@gmail.com avatar image bda2206@gmail.com brendan commented ·

regardless of what I try in the package field when I am testing in "try it" in the doco, I get the same error message.

even something simple like this which should object to no badge#

{ Title: "title" }

{
 "code": 400,
 "status": "BadRequest",
 "error": "InvalidParams",
 "errorCode": 1000,
 "errorMessage": "Invalid input parameters",
 "errorDetails": {
  "Title": [
   "The Title field is required."
  ],
  "Message": [
   "The Message field is required."
  ]
 },
 "CallBackTimeMS": 474
}
0 Likes 0 ·
Show more comments
bda2206@gmail.com avatar image bda2206@gmail.com commented ·

@brendan

I tried that, but the problem is the APS Content-Available key needs to be at the same level as Title and Message, but its nested under CustomData.

https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html

as you can see there are quite a few keys unavailable via playfab push, need to be able to add these in as needed... another field such as APS-Data to put these in would be great.

cheers

0 Likes 0 ·
brendan avatar image brendan bda2206@gmail.com commented ·

Sorry, I don't quite follow - are you saying that you're using content-available in CustomData, and you have your own custom plugin on the client side to interpret the CustomData, and that you're not able to use it?

0 Likes 0 ·
bda2206@gmail.com avatar image bda2206@gmail.com commented ·

I need to do a package that comes to the phone in this format

{ aps : { Badge: 1, content-available : 1, Message : "message", Title: "title" }}

not

{ aps : { Badge: 1, CustomData : { content-available : 1 }, Message : "message", Title: "title" }}

0 Likes 0 ·
brendan avatar image brendan bda2206@gmail.com commented ·

Ah, now I see what you're trying to do. The short answer is that no, we do not support all possible platform payload keys natively. You would need to use custom data in your Push together with your own plugin, in order to extend to the advanced features.

0 Likes 0 ·
bda2206@gmail.com avatar image bda2206@gmail.com brendan commented ·

What you describe defies the functionality of what the keys do with the data delivery on the phone.

if customdata presented its payload at the same level as the rest of the keys it would be ok. As it is, your push implementation is broken. :(

0 Likes 0 ·
Show more comments
bda2206@gmail.com avatar image bda2206@gmail.com commented ·

@brendan I appreciate not to break for existing systems, I was just describing the result I was after. An optional NativeKeys parameter would not break the functionality for existing users.

will do a feature request thanks

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.