首页 > 解决方案 > _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 => { });
        

我现在该怎么办?

标签: firebasereact-nativereact-native-firebase

解决方案


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 => { });
        

推荐阅读