首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用"react-native-firebase v6“将数据从通知传递到它打开的应用程序的最佳方法是什么?

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

Stack Overflow用户
提问于 2019-11-05 18:48:39
回答 1查看 146关注 0票数 0

我想实现在与Firebase发送的推送通知交互时打开特定的屏幕。我的理解是,我需要使用在react-native-firebase v5和更低版本中可用的getInitialNotification()函数,但在react-native-firebase v6中还不可用,因为通知包还没有准备好。其中,到目前为止,我已经尝试设置了云消息包中提供的后台消息处理程序,但它似乎不适用于非data-only消息:

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

我应该降级到react-native-firebase v5来使用他们的通知包中的getInitialNotification()吗,或者我还有其他更好的选择,比如使用android原生代码吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-11-28 21:36:09

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

代码语言:javascript
复制
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,
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58709750

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档