Firebase 云消息传递 - PHP REST API 无法在 iOS 上运行

Firebase Cloud Messaging - PHP REST API not working on iOS

我正在使用下面的 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) {}

您应该将 priority 设置为 high 而不是 10

当使用 GCM/FCM 时,priority 的唯一有效值是 normalhigh,它们等于 510对于 iOS 个 APN,如前所述 here:

Sets the priority of the message. Valid values are "normal" and "high." On iOS, these correspond to APNs priorities 5 and 10.