且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

设备上收到Firebase消息,但未通过通知显示

更新时间:2023-11-15 13:14:16

您正在发送 data - PHP中的有效负载:

You are sending a data-only payload in your PHP:

public function send($to, $message) {
    $fields = array(
        'to' => $to,
        //'data' => $message,
        'data' => array("message" => $message));

    return $this->sendPushNotification($fields);
}

您的其他方法也发送相同的内容.

如果要使用仅notification的有效负载,则可以像这样简单地构造它:

If you're going to use a notification-only payload, you could simply structure it like so:

public function send($to, $message) {
    $fields = array(
        'to' => $to,
        'notification' => array("title" => $title,
            "body" => $body));

    return $this->sendPushNotification($fields);
}

与从Firebase控制台发送消息的区别在于,来自控制台的消息被视为 notification 消息.

The difference from sending a message from the Firebase Console is that messages from the console are considered as notification messages.

在Android中,每种消息类型的处理方式都不同(请参见处理消息).

In Android, each message type is handled differently (see Handling Messages).

一些有用的帖子:

  • Issue with FCM notification
  • Can we push only data message from Firebase Notification console