使用“ react-native-firebase v6”将数据从通知传递到打开的应用程序的最佳方法是什么?

我想实现与Firebase发送的推送通知进行交互时打开特定屏幕的功能。我的理解是,我需要使用getInitialNotification()及更低版本中可用的react-native-firebase v5函数,但由于Notifications包尚未准备就绪,因此react-native-firebase v6中尚不可用。 除其他事项外,到目前为止,我已经尝试设置Cloud Messaging程序包中可用的后台消息处理程序,但是它似乎不适用于不是data-only消息的内容:

Firebase.messaging().setBackgroundMessageHandler(async (remoteMessage) => { await storeJSONData('notification',JSON.stringify(remoteMessage)); });

我应该降级到react-native-firebase v5以便从Notifications包中使用他们的getInitialNotification(),还是我有其他更好的选择,例如甚至使用android原生代码?

wcxoneper 回答:使用“ react-native-firebase v6”将数据从通知传递到打开的应用程序的最佳方法是什么?

我最终通过在Firebase云消息传递顶部使用react-native-push-notification包并从该包中实现onNotification函数来解决了这个问题。

PushNotification.configure({
      onNotification: function(notification)
      {
        // process the notification
        console.log('NOTIFICATION:',notification);
        //iOS only
        notification.finish(PushNotificationIOS.FetchResult.NoData);
      },permissions: {
        alert: true,badge: true,sound: true
      },popInitialNotification: true,requestPermissions: true,});
本文链接:https://www.f2er.com/3160279.html

大家都在问