0
我正在使用下面的PHP代码使用Firebase REST API向Android和iOS设备发送推送通知。推送通知在Android设备上很好。但它不是在iOS设备上。Firebase云消息传递 - PHP REST API不适用于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) {}
您可以打印出您的有效载荷是如何解释的?如果我正确地阅读它,它会显示一个有效载荷,其中''notification'在'data'内部?另外,尝试将'priority'设置为'high'而不是'10'。 –
是的。将优先级设置为高后,它工作正常。如果您将它作为答案发布,我会接受它。 – user10
我会继续做下去。 –