react-native-firebase:onNotificationOpenedApp 和 getInitialNotification 在 iOS 上不起作用
react-native-firebase: onNotificationOpenedApp and getInitialNotification not working on iOS
我正在使用来自 react-native-firebase 7.0.1 的云消息传递。
我不想在 firebase 中存储 iOS 设备令牌,所以我使用 getAPNSToken()
方法然后将其存储在我的后端。
我可以在设备上发送通知,按下它后,应用程序会打开。
但是当我尝试从 getInitialNotification()
或 onNotificationOpenedApp()
获取消息时,它总是 returns null
/undefined
.
它每次都在 Android 上运行。
PushHandler.js
import React from 'react';
import messaging from '@react-native-firebase/messaging';
export default class PushHandler extends React.Component {
constructor(props) {
super(props);
this.messageApp = messaging();
}
componentDidMount() {
this.messageApp.onNotificationOpenedApp(remoteMessage => {
if (remoteMessage) { // <- always null on iOS
// handle notification
}
});
this.messageApp.getInitialNotification().then(initialMessage => {
if (initialMessage) { // <- always undefined on iOS
// handle notification
}
});
}
render() {
return null;
}
}
刚刚意识到根据文档,这些功能仅在通过 FCM 发送和接收通知时有效,这就是为什么您在通过 APNS 手动发送通知时看不到这些功能的原因。
此包将允许利用 getInitialNotification 和其他函数:https://github.com/react-native-community/push-notification-ios
以前用过。我的意思是,对于 RNFirebase 5.x.x 版本。
出于某种原因,库的维护者决定仅在 Firebase 云消息通过时才将这些事件发送到 JS 层。
我删除了 IF 语句,它似乎像以前一样工作。
但是,是的,这就是 RN-Firebase 库的新行为。
我正在使用来自 react-native-firebase 7.0.1 的云消息传递。
我不想在 firebase 中存储 iOS 设备令牌,所以我使用 getAPNSToken()
方法然后将其存储在我的后端。
我可以在设备上发送通知,按下它后,应用程序会打开。
但是当我尝试从 getInitialNotification()
或 onNotificationOpenedApp()
获取消息时,它总是 returns null
/undefined
.
它每次都在 Android 上运行。
PushHandler.js
import React from 'react';
import messaging from '@react-native-firebase/messaging';
export default class PushHandler extends React.Component {
constructor(props) {
super(props);
this.messageApp = messaging();
}
componentDidMount() {
this.messageApp.onNotificationOpenedApp(remoteMessage => {
if (remoteMessage) { // <- always null on iOS
// handle notification
}
});
this.messageApp.getInitialNotification().then(initialMessage => {
if (initialMessage) { // <- always undefined on iOS
// handle notification
}
});
}
render() {
return null;
}
}
刚刚意识到根据文档,这些功能仅在通过 FCM 发送和接收通知时有效,这就是为什么您在通过 APNS 手动发送通知时看不到这些功能的原因。
此包将允许利用 getInitialNotification 和其他函数:https://github.com/react-native-community/push-notification-ios
以前用过。我的意思是,对于 RNFirebase 5.x.x 版本。 出于某种原因,库的维护者决定仅在 Firebase 云消息通过时才将这些事件发送到 JS 层。
我删除了 IF 语句,它似乎像以前一样工作。 但是,是的,这就是 RN-Firebase 库的新行为。