问题描述
我处理了文档并将其应用迁移到版本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 => { });