2

我正在尝试为我们的iOS应用程序接收“数据”有效负载通知。如果发送“数据”(但是“通知”有效)有效载荷到iOS中的GCM/FCM,则不会收到推送通知didReceiveRemoteNotification

今天,我们可以发送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_##" 
} 
' 

这将成功触发iOS AppDelegate.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上,数据有效载荷可以在Intent检索用于启动您的活动。
  • 在iOS上,数据有效载荷将在didReceiveRemoteNotification:中找到。

GCM可以处理纯data推送通知的APN网络吗?

我需要做什么特别的事情才能收到data,与notification相比,推送通知在iOS?

从您分享的笔记
+0

也许由于这个https://开头计算器的.com /一个/80389分之36019064 – corgrath

回答

0

除此之外,请不要错过指出,

在iOS上,GCM存储邮件,并提供它,只有当应用程序在前台运行,并已建立了GCM连接。

有了这个,你可能想检查Establishing a Connection。然后,当您的XMPP连接建立时,CCS和您的服务器使用正常的XMPP节来回发送JSON编码的消息。所述<message>的主体必须是:

<gcm xmlns:google:mobile:data> 
    JSON payload 
</gcm> 

此外,请注意message_id是数据消息的必需字段。检查此示例请求格式以获取带有有效负载的消息 - 数据消息显示在Downstream Messages中。你只需要使用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 
    } 
    </gcm> 
</message> 

欲了解更多信息,请参阅XMPP Connection Server Reference

0

当与FCM发送数据类型消息,iOS设备,它们将仅content_available在您的FCM请求主体设置为true,如收到:

{ 
    "to": "--fcm-token--", 
    "content_available": true, 
    "data": { 
     "priority": "high", 
     "hello": "world" 
    } 
} 
相关问题