我正在使用react-native-firebase 7.0.1的Cloud Messaging。
我不想在firebase中存储iOS设备令牌,所以我使用了 getAPNSToken()
方法,然后存储在我的后台。
我可以在设备上发送通知,并且在按下通知后,应用程序会打开。
但是,当我试图从 getInitialNotification()
或 onNotificationOpenedApp()
它总是返回 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.comreact-native-communitypush-notification-ios。