2016-09-26 57 views
0

我對Google FCM很困惑。 文檔頁面https://firebase.google.com/docs/cloud-messaging/http-server-ref列出了API支持的參數,但奇怪的是,「badge」參數僅顯示爲「iOS」。谷歌FCM:徽章櫃檯限於iOS?

我正在設置我的android應用程序徽章計數器,直到上週成功,但今天,在「通知」部分發送參數「徽章」不起作用。通知成功到達。

我通知數據結構:

Array 
(
    [to] => (device token) 
    [notification] => Array 
     (
      [title] => Title 
      [text] => Test message 
      [sound] => default 
      [vibrate] => 1 
      [badge] => 2 
     ) 
) 

我的服務器端代碼(PHP):

$jsonData = json_encode($data); 

$ch  = curl_init("https://fcm.googleapis.com/fcm/send"); 
$header = array(
    'Content-Type: application/json', 
    "Authorization: key=".MY_GCM_API_KEY 
); 

curl_setopt($ch, CURLOPT_HTTPHEADER, $header); 
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, true); 
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true); 

curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData); 

$result = curl_exec($ch); 
curl_close($ch); 

回答

1

Android不支持應用程序的圖標徽章代表非再現通知。
(一些設備製造商添加了這個功能比較熟悉的iOS,但它是設備上的自定義功能,而且也沒有一個標準的Android API)

當您發送FCM消息時,badge參數在iOS中正確使用,但由於上述說明,在Android上簡單忽略了

PS:這是自GCM/FCM中引入API以來的行爲。

+0

嗯...這個答案現在仍然有效嗎? – Ionut

+0

是的。在O android中引入了徽章,但它們是由系統自動處理的,無法控制。 –