【问题标题】:How to receive notifications from Firebase Cloud Messaging in React Native如何在 React Native 中接收来自 Firebase 云消息传递的通知
【发布时间】:2021-08-04 04:31:46
【问题描述】:

我有一个 React Native 项目,希望能够接收来自 FCM 的通知。我已经设置了项目(为我的项目生成了一个 google-services.json 文件,相应地修改了 build.gradle 文件等),但到目前为止我还无法运行该项目。我正在使用 React Native Firebase 库https://rnfirebase.io/,但到目前为止体验并不好。我一直在错误中跌跌撞撞,如下所示:

Error: You attempted to use a firebase module that's not installed on your Android project by calling firebase.app().

Ensure you have:

1) imported the 'io.invertase.firebase.app.ReactNativeFirebaseAppPackage' module in your 'MainApplication.java' file. 
2) Added the 'new ReactNativeFirebaseAppPackage()' line inside of the RN 'getPackages()' method list.

我刚刚完成了让工具正常工作的尝试。你能告诉我还有什么其他方法可以让 Firebase 通知为不使用上述库的 React Native 项目工作吗?

【问题讨论】:

    标签: android ios reactjs firebase react-native


    【解决方案1】:

    您是否按照错误消息中的建议进行操作?还有什么可以工作是删除你的android项目的构建和缓存,然后重建应用程序。您使用的是哪个版本的 firebase?

    【讨论】:

    • 您好,我已经删除了构建目录并重新编译了项目。我去查看其他帖子并设法让项目运行,但应用程序立即崩溃。我不明白为什么下面的代码甚至都没有说出问题所在:messaging() .getToken() .then(token => { console.log(token); }) .catch(err => { console.log(err); }); 上面的消息传递()函数是从@react-native-firebase/messaging 包中导入的。它只是
    猜你喜欢
    • 2022-07-20
    • 1970-01-01
    • 2017-05-05
    • 1970-01-01
    • 1970-01-01
    • 2020-01-02
    • 2020-07-28
    • 2020-07-16
    • 2019-02-06
    相关资源
    最近更新 更多