firebase - _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 => { });
推荐阅读
- javascript - Yii2 图表未定义
- pyspark - 从 Notebook 的下拉菜单中获取参数
- .net - 疑难解答 - 如何在 Windows 2008 Server SP2 上启用 TLS 1.2
- rust - 有没有办法在 Serde 的序列化输出中添加一个常量字段?
- sql - 从 SQL Server 中的 XML 数据类型字段中提取数据
- css - 相对于子组件定位父组件
- mysql - MySQL计算空值
- python - sklearn:无法从“sklearn.utils”导入名称“可索引”
- python-3.x - Spacy -- ImportError: preshed.maps 没有导出预期的 C 函数 map_clear
- c - 将 __attribute__((used)) 设置为 C 变量/常量无效