Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
Ask Question
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"
On iOS, GCM stores the message and delivers it only when the app is in the foreground and has established a GCM connection.
With this, you may want to check Establishing a Connection. Then, when your XMPP connection is established, CCS and your server use normal XMPP <message>
stanzas to send JSON-encoded messages back and forth. The body of the <message>
must be:
<gcm xmlns:google:mobile:data>
JSON payload
Also, note that message_id
is a required field for data message. Check this sample request format for message with payload - data message shown in Downstream Messages. You just have to convert it using CURL.
<message id="">
<gcm xmlns="google:mobile:data">
"to":"REGISTRATION_ID", // "to" replaces "registration_ids"
"message_id":"m-1366082849205" // new required field
"data":
"hello":"world",
"time_to_live":"600",
"delay_while_idle": true/false,
"delivery_receipt_requested": true/false
</message>
For more information, see XMPP Connection Server Reference.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.