Using data only in push payload is not valid on all platforms #1828
Comments
Although you're correct in interpreting that chunk of text from the docs by itself, there is context around it: it applies only to the Android section of the payload docs. So, you should read (or we should reword it to be more readable):
|
There is no way as of right now, to specify a single payload that works 100% on both/all platforms. You'll need to differ your users/targets on the server, and send a separate payload for each of them ( |
@MarsupiL Yeah, the problem on Android is the way Google sets up when the You will need to segment your pushes via the Android, iOS lines in order for this to work. It's really not that difficult on the server side to do this you just need to let your server know if the device is Android or iOS when you send it the registration token. |
So I assume from the responses that the 2 different payloads will still be needed in v2 of this plugin using FCM, correct? Maybe it'd help to clarify this in the overview part of the Payload doc.
and
|
I am having the same issue. This problem becomes very apparent when you are sending to topics. I want all my platforms to subscribe to a single topic so that I can send a single POST to that topic which should send a notification to any platform subscribed. However, I cannot send one POST that iOS and Android both can use. I also cannot send only to iOS or only to Android when sending to a topic (as both platforms are subscribed). The only work around for me is to split all my topics up by platform. So instead of having a 'general' topic I will now have a 'General iOS' topic and 'General Android' topic. The device code will need to be smart enough to know which topic to subscribe to. When sending a notification, the notification will need to be sent to both topics now in 2 seperate POSTs which does defeat the purpose of FCM and adds a lot of complexity. If I was sending to an individual device then this would be easy. Hope this helps give some perspective on how this can be a real issue moving forward. Appreciate all the work. |
@MarsupiL that is correct. The 2 different payloads will still be needed. @sawest I'm aware that this is a real issue. It's been one ever since GCM was supported on iOS. Sadly, there doesn't appear to be anything I can do. In your app you can use the device plugin to determine which platform you are running on and subscribe the the correct topic. |
So, if I'm understanding this correctly: Using DATA ONLY payloads for Android is best because it will be received in all app states (Background, Foreground and Closed). The developer can then handle the different situations depending on the app state.
However, on the iOS side of the world, just data payloads don't work? So you need to include a notification. iOS Example:
So we could probably put a "band-aid" on this issue by sending two separate messages? One with a data only payload and one with a notification payload? The one with the data only payload wouldn't be read by the iOS apps and the one with the notification payload wouldn't be read by Android apps. Am I understanding this correctly? Thanks all, |
Hi there ! Using HTTPv1 FCM API, I manage to handle background notification the right way with both Android and iOS.
both on android and ios my event is fired directly when in foreground or it is fired on notification click when in background. Hope it will inspire you to use this API (sorry I can't find how to format this json to make it readable) {
"validateOnly":false,
"message":{
"data":{
"data1":"value1"
},
"android":{
"data":{
"data1":"value1",
"title":"Hello",
"body":"Please confirm your availability"
},
"restricted_package_name":"com.test.app",
"priority":"high"
},
"name":"Planning validation",
"apns":{
"payload":{
"aps":{
"alert":{
"title":"Hello",
"body":"Please confirm your availability"
}
}
}
},
"token":"[valid FCM token]"
}
} |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Expected Behaviour
According to the plugin doc:
...my recommended format for your push payload when using this plugin (while it differs from Google's docs) works 100% of the time
Actual Behaviour
Having both
notification
anddata
is the only way I managed to get the notifications to open the app on both platforms. But the on('notification') handler is never called in Android and is randomly called in iOS.Having all data under
data
does not trigger any notification in iOS even though Firebase returns a successful request because the forwarded APNS payload is not correct.Besides the proper way should be to follow the GCM or FCM payload recommendations, which is to use both
notification
for the notification message anddata
for custom key/value pairs. Like so:Sample requests to reproduce:
or
I see through other issues in this plugin that we should use different payloads for the different platforms. This adds too much complexity on the server side and is again defeating the purpose of GCM/FCM that do work with a single payload for both platforms.
Could you please confirm that this is indeed a bug and whether it will be fixed in the next stable FCM version of this plugin?
Thanks for the effort.
cordova 6.5.0
cordova android 6.2.2
cordova ios 4.4.0
phonegap-plugin-push 1.10.5
The text was updated successfully, but these errors were encountered: