【发布时间】:2017-12-04 10:39:30
【问题描述】:
我正在尝试为我们的 iOS 应用获取“数据”有效负载通知。
今天我们可以按照以下方式发送 GCM notification 推送通知:
https://developers.google.com/cloud-messaging/concept-options
(FCM有相同的文字)
一个简单的测试是使用 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_##"
}
'
这将成功触发iOSAppDelegate.didReceiveRemoteNotification:fetchCompletionHandler函数。
但是,如果将其更改为data 通知:
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_##"
}
'
我看不到任何东西从 GCM 发送到应用程序(在 didReceiveRemoteNotification 函数中),即使应用程序处于后台/前台。
即使它在文档中说它应该:
https://developers.google.com/cloud-messaging/concept-options#notifications_and_data_messages
请注意这些平台特定的详细信息:
- 在 Android 上,可以在用于启动 Activity 的 Intent 中检索数据负载。
- 在 iOS 上,数据负载将在 didReceiveRemoteNotification: 中找到。
GCM 可以处理纯data 向 APN 网络推送通知,对吗?
与notification 相比,iOS 中的推送通知我是否需要做一些特别的事情才能接收data?
【问题讨论】:
-
是的,我遇到了同样的问题。找到解决办法了吗?
标签: ios notifications google-cloud-messaging firebase-cloud-messaging