我对 Google FCM 很困惑。 文档页面 https://firebase.google.com/docs/cloud-messaging/http-server-ref列出了 API 支持的参数,但奇怪的是,“badge”参数仅显示为“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);
最佳答案
Android 不支持应用程序图标上的徽章来表示未读通知。
(一些设备制造商添加此功能以更熟悉 iOS,但它是该设备上的自定义功能。没有标准的 Android API)
当您发送 FCM 消息时,badge
参数在 iOS 中被正确使用,但由于上述解释,它在 Android 上被简单地忽略了。
PS:这是自从在 GCM/FCM 中引入 API 以来的行为。
关于php - 谷歌 FCM : badge counter restricted to iOS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39713282/