Jak*_* G. 2 push-notification ios firebase react-native react-native-firebase
我正在使用 react-native-firebase 7.0.1 中的云消息传递。
我不想在 firebase 中存储 iOS 设备令牌,所以我使用getAPNSToken()方法然后将它存储在我的后端。
我可以在设备上发送通知,按下它后,应用程序就会打开。
但是当我尝试从getInitialNotification()or获取消息时,onNotificationOpenedApp()它总是返回null/ undefined。
它每次都适用于Android。
推送处理程序
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;
}
}
Run Code Online (Sandbox Code Playgroud)
小智 5
刚刚意识到,根据文档,这些功能仅在通过 FCM 发送和接收通知时才有效,这就是为什么在通过 APNS 手动发送通知时您看不到这些功能的原因。
这个包将允许利用 getInitialNotification 和其他功能:https : //github.com/react-native-community/push-notification-ios
| 归档时间: |
|
| 查看次数: |
2297 次 |
| 最近记录: |