我使用下面的PHP代码发送推送通知到Android和iOS设备使用Firebase REST API。推送通知在Android设备上运行良好。但它不会出现在iOS设备上。
同时,当我从Firebase控制台发送通知时,两个设备都收到了它。我在我的API实现中遗漏了什么吗?
$data = array("to" => "/topics/news",
'priority' => '10',
'notification' => array('body' => $msg));
$headers = array
(
'Authorization: key='.$apiKey,
'Content-Type: application/json'
);
try {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://fcm.googleapis.com/fcm/send");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$ouput = curl_exec($ch);
if ($ouput === false) {
throw new Exception(curl_error($ch), curl_errno($ch));
}
$response = curl_getinfo($ch);
} catch(Exception $e) {}
您应该将priority
设置为high
而不是10
。
当使用GCM/FCM时,priority
的唯一有效值是normal
和high
,等于iOS apn的5
和10
,正如这里提到的:
设置消息的优先级。有效值为normal和high。在iOS上,这些对应于apn优先级5和10。