iOS FCM data only message does not call messaging:didReceiveMessage

こ雲淡風輕ζ 提交于 2019-12-23 06:04:11

问题


Firebase Messaging version 5.6.0. I am attempting to handle a data only message in the foreground via Firebase Messaging on iOS 9.0 (10 if needed), but it is not calling FIRMessagingDelegate's messaging:didReceiveMessage per the documentation. I see the message come in @ FIRMessaging.m's appDidReceiveMessage:message, but never comes through to the delegate.

This is the snippet from the cloud function that sends data to the topic per sending to a topic:

const message = {
  data: {
    test: '123'
  }
  topic: 'example'
}
admin.messaging().send(message);

Did I miss something?

Update: I do receive the data if I implement application:didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler.


回答1:


Thanks to Kat at Firebase support, here is the answer.

Use legacy sendToTopic instead of send, as send quietly adds content_available=1 which gets treated as APNs silent notification. Here is the updated version:

admin.messaging().sendToTopic('example', {
  data: {
    test: '123'
  }
});
// Always use strings for key/values in the data object.

Below verbatim from Kat at Firebase support:

How the FCM data message is handled would depend on your setting for content_available.

  • If you have content_available = 1, the message is sent via APNs and is treated similar as an APNs silent notification. This is handled in the application:didReceiveRemoteNotification: callback when the app is running in foreground or background (i.e. not killed). See this related StackOverflow post for more information.

  • Without content_available, the message is sent via FCM direct channel. This only handled in the messaging:didReceiveMessage: when app is in foreground.

Note that messages sent via the Admin SDK's send() method uses the FCM HTTP v1 API which have content_available=1 by default, so they are always sent via APNs. If you want to configure the content_available field, you'll need to use the Admin SDK's sendToDevice() method which uses the legacy protocols.

In addition, here is the list of legacy protocols.



来源:https://stackoverflow.com/questions/51953211/ios-fcm-data-only-message-does-not-call-messagingdidreceivemessage

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