【发布时间】:2018-08-09 16:55:53
【问题描述】:
我正在使用react-native-firebase 向应用程序发送推送消息,它看起来很棒!另外,我需要接收部分数据,所以发送类似这样的数据
$request_body = [
'to' => $TOKEN_ID,
'notification' => [
'title' => 'Title',
'body' => 'Body',
'sound' => 'default',
],
'data' => [
'key' => 'value',
],
];
我正在尝试收听打开的推送消息事件,如下所示
this.notificationOpenedListener = firebase.notifications().onNotificationOpened((notificationOpen) => {
const notification = notificationOpen.notification;
const data = notificationOpen.data;
setTimeout(() => {
Alert.alert(data.key);
}, 5000);
});
5 秒后,应用程序关闭,没有任何错误消息。如果将Alert.alert(data.key); 更改为Alert.alert(notification.title); 应用程序工作正常并显示警报。有人可以向我解释一下,为什么无法正常检索数据?
【问题讨论】:
标签: firebase react-native push-notification firebase-cloud-messaging