【发布时间】:2020-10-28 01:11:41
【问题描述】:
我正在开发一个通过 Firebase 云消息传递获取推送通知的原生反应项目。已实现 onNotification()、onNotificationOpened() 和 getInitialNotification() 方法。虽然当应用程序处于前台并强制关闭时通知正常工作,但在应用程序处于后台时打开通知时出现错误(不是强制关闭)。错误图像如下。我尝试更改/评论通知代码,但错误仍然存在。我对 React Native 很陌生,不知道为什么会发生这个特殊问题。在这方面的任何帮助都会非常有帮助。我已经更新了与 firebase 和云消息传递相关的所有 pod。下面也是 react-native 代码。我没有在 Xcode 中进行任何编码,所以 Pod 文件是原样的。 [在此处输入图片说明][1]
![1]:https://i.stack.imgur.com/Bg7Us.png
async createNotificationListeners() {
this.notificationListener = firebase.notifications().onNotification((notification) => {
if (notification) {
//const {title, body, data} = notification;
//this.displayNotification(title, body, data);
}
});
this.notificationOpenedListener = firebase.notifications().onNotificationOpened((notification) => {
const {data} = notification.notification;
if (data.url !== undefined) {
this.navigate2URL(data.url);
}else {
this.setState({url: 'test'});
this.webRef.reload();
}
//this.displayNotification(title, body + data);
});
const notificationOpen = await firebase.notifications().getInitialNotification();
if (notificationOpen) {
const {data} = notificationOpen.notification;
if (data.url !== undefined) {
this.setState({url: data.url});
} else {
this.setState({url: 'test'});
}
this.webRef.reload();
//this.displayNotification(title, body);
}
}
【问题讨论】:
-
你能添加一些代码吗...以便我们提供帮助。
-
我遇到了完全相同的问题.. 使用 iOS 14 和 react-native-firebase 5.5.6
-
这个问题解决了吗?我也面临同样的问题。
标签: ios react-native firebase-cloud-messaging react-native-ios