我正在使用 https://github.com/arnesson/cordova-plugin-firebase/在基于 ionic 的应用程序上接收 Google Firebase 消息。
设置证书、安装插件和设置 Firebase 帐户后,我能够收到通过 Firebase 控制台发送的通知(在 Android 和 iOS 设备上)。
但是当我通过 Firebase API ( https://firebase.google.com/docs/cloud-messaging/http-server-ref ) 发送时,只有安卓设备会收到通知。我正在使用以下代码:
$data = Array
(
[to] => <token>
[notification] => Array
(
[title] => My Title
[text] => Notification test
[sound] => default
[vibrate] => 1
[badge] => 0
)
)
$jsonData = json_encode($data);
$ch = curl_init("https://fcm.googleapis.com/fcm/send");
$header = array(
'Content-Type: application/json',
"Authorization: key=".$gcmApiKey
);
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);
echo $result;
没有返回错误:
{"multicast_id":904572753471539870406,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1477063422322568734%3d5c78243d5c7824"}]}
有什么问题吗?
最佳答案
对于 iOS,尝试在您的负载中添加参数 priority
设置为 high
和 content_available
设置为 true
.
查看参数详情here .
关于php - Google Firebase iOS 推送在控制台中有效,但在 API 中无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40182345/