I am trying to get "data" payload notifications to be received for our iOS app.
Today we can send GCM notification
push notifications as according to:
https://developers.google.com/cloud-messaging/concept-options
(FCM has the same text)
An easy test is using CURL:
curl -X POST \
https://gcm-http.googleapis.com/gcm/send \
-H 'authorization: key=##_GCM_SERVER_ID_##' \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
-H 'postman-token: ##_POSTMAN_TOKEN_##' \
-d '{
"notification": {
"body": "Test body"
},
"to" : "##_DEVICE_TOKEN_##"
}
'
This will successfully trigger iOS AppDelegate.didReceiveRemoteNotification:fetchCompletionHandler
function.
However, if change it to a data
notification:
curl -X POST \
https://gcm-http.googleapis.com/gcm/send \
-H 'authorization: key=##_GCM_SERVER_ID_##' \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
-H 'postman-token: ##_POSTMAN_TOKEN_##' \
-d '{
"data": {
"body": "Test body"
},
"to" : "##_DEVICE_TOKEN_##"
}
'
I can't see anything is being sent to the app from GCM (in either didReceiveRemoteNotification
functions), even if the app is in background/foreground.
Even though it says in the documentation it should:
https://developers.google.com/cloud-messaging/concept-options#notifications_and_data_messages
Note these further platform-specific details:
- On Android, data payload can be retrieved in the Intent used to launch your activity.
- On iOS, data payload will be found in didReceiveRemoteNotification:.
GCM can handle pure data
push notifications to the APN network right?
Do I need to do anything special to receive data
, compared to notification
, Push Notifications in iOS?
When sending the Data type message with FCM to iOS devices, they will only be received if content_available
is set to true
in your FCM request body, eg:
{
"to": "--fcm-token--",
"content_available": true,
"data": {
"priority": "high",
"hello": "world"
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With