【问题标题】:Firebase Cloud Messaging PHP Integration send push notificationFirebase 云消息传递 PHP 集成发送推送通知
【发布时间】:2017-03-29 06:04:19
【问题描述】:

我在 PHP 中集成了 FCM 推送通知功能。现在,通知工作正常,但badge 号码不起作用。

我添加了badge = 1,但每次都没有显示 1 而不是递增徽章编号。我想发送自动递增的徽章编号。

请看我的php文件代码:

 <?php

    $ch = curl_init("https://fcm.googleapis.com/fcm/send");

    //The device token.
    $token = "DEVICE_TOKEN_HERE"; //token here 

    //Title of the Notification.
    $title = "Title Notification";

    //Body of the Notification.
    $body = "This is the body show Notification";

    //Creating the notification array.
    $notification = array('title' =>$title, 'text' => $body, 'sound' => 'default', 'badge' => '1');

    //This array contains, the token and the notification. The 'to' attribute stores the token.
    $arrayToSend = array('to' => $token, 'notification' => $notification,'priority'=>'high');

    //Generating JSON encoded string form the above array.
    $json = json_encode($arrayToSend);
    //Setup headers:
    $headers = array();
    $headers[] = 'Content-Type: application/json';
    $headers[] = 'Authorization: key=API_KEY_HERE'; // key here

    //Setup curl, add headers and post parameters.
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
    curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
    curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);       

    //Send the request
    $response = curl_exec($ch);

    //Close request
    curl_close($ch);
    return $response;

?>

请帮帮我!!!谢谢。

【问题讨论】:

    标签: php ios firebase push-notification firebase-cloud-messaging


    【解决方案1】:

    这是预期的行为。 iOS 不会自动增加您发送的徽章。在发送之前,您必须在服务器端确定徽章的应有值。

    另见post

    【讨论】:

    • 谢谢 AL 我已经阅读了这篇文章,之后我正在从我的服务器端管理徽章,它工作正常。 :)
    • 酷。干杯。 :)
    猜你喜欢
    • 2016-12-13
    • 1970-01-01
    • 2017-11-18
    • 1970-01-01
    • 2020-08-14
    • 1970-01-01
    • 2021-11-02
    • 2017-10-04
    • 2017-03-10
    相关资源
    最近更新 更多