【发布时间】:2016-10-03 14:29:07
【问题描述】:
我正在使用以下 PHP 代码使用 Firebase REST API 向 Android 和 iOS 设备发送推送通知。推送通知在 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) {}
【问题讨论】:
-
你能打印出你的有效载荷是如何解释的吗?如果我没看错,它会显示一个有效负载,您的
notification在data内?另外,尝试将priority设置为high而不是10。 -
是的。将优先级设置为高后,它工作正常。如果您将其发布为答案,我会接受。
-
我会继续做的。
标签: php android ios google-cloud-messaging firebase-cloud-messaging