_app.default.messaging.notifications不是通过迁移到react-native-firebase v6的功能

问题描述

我处理了文档并将其应用迁移到版本6,但出现此错误

TypeError: _app.default.messaging.notifications is not a function.
 (In '_app.default.messaging.notifications()','_app.default.messaging.notifications' is undefined)

这是我的代码 如果要做其他事情,我保留了以前的一切

.
.
import firebase from '@react-native-firebase/app';
import '@react-native-firebase/messaging';
.
.


    firebase.messaging.notifications().onNotification(Notification => {
        var messageData = Notification.data;
        var messageType = messageData.type;

        var DBbadgeCount = parseInt(messageData.badgeCount);
            this.props.Increment_RequestCount();
            firebase.messaging
                .notifications()
                .getBadge()
                .then(count => {
                    if (count !== DBbadgeCount) {
                        firebase.messaging.notifications().setBadge(DBbadgeCount);
                    }
                })
                .then(() => { })
                .catch(error => { });
        

我现在应该做什么?

解决方法

v6拆分了程序包,您不再从应用程序导入消息,而是从@react-native-firebase/messaging程序包导入消息。 @react-native-firebase/app仅需要安装,但无需导入。

.
.
import messaging from '@react-native-firebase/messaging';
.
.
   messaging.notifications().onNotification(Notification => {
        var messageData = Notification.data;
        var messageType = messageData.type;

        var DBbadgeCount = parseInt(messageData.badgeCount);
            this.props.Increment_RequestCount();
           messaging
                .notifications()
                .getBadge()
                .then(count => {
                    if (count !== DBbadgeCount) {
                       messaging.notifications().setBadge(DBbadgeCount);
                    }
                })
                .then(() => { })
                .catch(error => { });
        

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...