2

我正在尝试从我的服务器发送 FCM数据消息。这是消息请求的样子:

POST https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA

{ "data": {
    "score": "5x1",
    "time": "15:10"
  },
  "to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1..."
}

或者,当我使用PyFcm

push_service = FCMNotification(api_key=MY_API_KEY)
data_payload = {"score": "5x1", "time": "15:10"}
push_service.notify_single_device(registration_id="bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...", data_message=data_payload)

我通过省略该notification部分来确保它是一条数据消息。这样,根据FCM 指南,当应用程序处于后台或前台时,将调用onMessageReceived()a 。FirebaseMessagingService

但是,当应用程序关闭时,有时onMessageReceived()会调用,有时不会。我有什么办法可以确保它始终被调用,即使应用程序关闭也是如此?

4

0 回答 0