gpt4 book ai didi

javascript - 可能未处理的 promise 拒绝 ID : Invalid FCM Event subscription

转载 作者:行者123 更新时间:2023-11-29 19:06:44 25 4
gpt4 key购买 nike

Index.js

import FCM from "react-native-fcm";

class Register extends Component {
constructor(props) {
super(props);
componentDidMount () {
// this method generate fcm token.
FCM.requestPermissions();
FCM.getFCMToken().then(token => {
console.log("TOKEN (getFCMToken)", token);
});

// This method get all notification from server side.
FCM.getInitialNotification().then(notif => {
console.log("INITIAL NOTIFICATION", notif)
});

// This method give received notifications to mobile to display.
this.notificationUnsubscribe = FCM.on("notification", notif => {
console.log("a", notif);
if (notif && notif.local_notification) {
return;
}
this.sendRemote(notif);
});

// this method call when FCM token is update(FCM token update any time so will get updated token from this method)
FCM.on("refreshToken", token => {
console.log("TOKEN (refreshUnsubscribe)", token);
this.props.onChangeToken(token);
});
}
sendRemote(notif) {
console.log('send');
FCM.presentLocalNotification({
title: notif.title,
message: notif.message,
priority: "high",
click_action: notif.click_action,
show_in_foreground: true,
local: true
});
}
componentWillUnmount() {
this.refreshUnsubscribe();
this.notificationUnsubscribe();
}

这是我用于生成 token 和处理来自服务器的通知的代码的一部分。我做错了什么?想不通。请帮忙。提前致谢。下面是我得到的警告错误的截图。

fcm event error

最佳答案

我知道这为时已晚,但遇到了同样的问题,我通过导入修复了它

import FCM, {FCMEvent} from "react-native-fcm";

然后使用 FCMEvent 订阅事件:

this.notificationSubscribe = FCM.on(FCMEvent.Notification, notif => {
this.showNotification(notif);
});

关于javascript - 可能未处理的 promise 拒绝 ID : Invalid FCM Event subscription,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46949027/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com