【问题标题】:Firebase Cloud Messaging - PHP REST API not working on iOSFirebase 云消息传递 - PHP REST API 无法在 iOS 上运行
【发布时间】: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) {}

【问题讨论】:

  • 你能打印出你的有效载荷是如何解释的吗?如果我没看错,它会显示一个有效负载,您的notificationdata 内?另外,尝试将priority 设置为high 而不是10
  • 是的。将优先级设置为高后,它工作正常。如果您将其发布为答案,我会接受。
  • 我会继续做的。

标签: php android ios google-cloud-messaging firebase-cloud-messaging


【解决方案1】:

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

当使用 GCM/FCM 时,priority 的唯一有效值是 normalhigh,它们等于 iOS APNs 的 510,正如前面提到的 here

设置消息的优先级。有效值为“正常”和“高”。在 iOS 上,这些对应于 APN 优先级 5 和 10。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-24
    • 2020-10-11
    • 1970-01-01
    • 2019-07-12
    • 1970-01-01
    • 1970-01-01
    • 2020-07-10
    • 1970-01-01
    相关资源
    最近更新 更多