Ensuring onMessageReceived() is invoked when a FCM data message is sent even when App is closed

扶醉桌前 提交于 2019-12-02 02:00:16

问题


I am trying to send FCM data messages from my server. This is how a message request looks like:

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..."
}

or, when I use 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)

I made sure it is a data message by leaving out the notification part. In this way, according to the FCM guide, onMessageReceived() of a FirebaseMessagingService will be invoked when an app is in the background or the foreground.

However when the app is closed, sometimes onMessageReceived() is invoked, and sometimes it is not. Is there any way for me to make sure it is always invoked, even when the app is closed?

来源:https://stackoverflow.com/questions/44193726/ensuring-onmessagereceived-is-invoked-when-a-fcm-data-message-is-sent-even-whe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!