firebase.notifications() 在 react-native-firebase 中抛出错误

firebase.notifications() is throwing error in react-native-firebase

我已成功将 firebase 集成到我的移动应用程序中。现在我正在 android 上测试它。我正在成功收到通知。我的下一步是在应用程序处于前台和后台时触发事件并读取数据。为此,我查看了文档并使用了 firebase.notifications().displayNotification()。但它是抛出错误。

Ensure you have:

1) Installed the required Firebase Android SDK dependency 'com.google.firebase:firebase-notifications' in your 'android/app/build.gradle' file.

2) Imported the 'io.invertase.firebase.notifications.RNFirebaseNotificationsPackage' module in your 'MainApplication.java' file. 3) Added the 'new RNFirebaseNotificationsPackage()' line inside of the RN'getPackages()' method list.

听起来您需要按照 this page 上的说明安装通知依赖项。他们最近重写了 react-native-firebase 的通知部分,因此您的用例可能也需要它。

我遇到了同样的错误错误:您试图通过使用 invertase firebasev6 调用 firebase.notifications() 来使用未安装在您的 Android 项目中的 firebase 模块...

经过一些研究,我发现通知应该在 rnfirebase.io 中实现,即 firebase v5 和更小的

因此,invertase 决定不在他们的 firebase 包 v6 中使用通知。

要使用通知,当文档处于 alpha 版本时,您可以参考他们的通知包,或者您可以使用 wix/react-native-notifications 等...这是额外的包