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" 
    } 
} 
相關問題