ios - react-native-firebase:onNotificationOpenedApp 和 getInitialNotification 在 iOS 上不起作用
问题描述
我正在使用 react-native-firebase 7.0.1 中的云消息传递。
我不想将 iOS 设备令牌存储在 Firebase 中,所以我使用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.com/react-native-community/push-notification-ios
推荐阅读
- python - 如何从一个 xpath 选择器中获取一组值(多个值)?
- javascript - 量角器中使用 gettext() 函数并在其他文件中使用它时出现未定义错误
- c# - 在表单关闭 C# 上清除剪贴板
- node.js - 来自 node_modules 的 Node.js 10 require('...') 非常慢
- python - 设置背景后运行turtle模块出错
- javascript - 蹦床功能操作原理
- ios - 如何使用 swift 4.2 在泛型类中创建单例?
- c++ - 一个使用 QtUdpSocket 的简单通信 c/s 应用程序
- android - 反应原生滚动视图不在android上滚动
- laravel - 如何在 laravel 5.7 中从 mandrill 获得邮件回复?