Firebase云消息- PHP REST API不能在iOS上工作


Firebase Cloud Messaging - PHP REST API not working on iOS

我使用下面的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的唯一有效值是normalhigh,等于iOS apn的510,正如这里提到的:

设置消息的优先级。有效值为normal和high。在iOS上,这些对应于apn优先级5和10。