如何解决_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 => { });
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。