如何解决当应用处于后台状态时,无法从推送通知中获取标题和消息
我正在尝试构建react-native应用程序,该应用程序具有使用react-native-push-notification实现的推送通知。现在,当应用程序处于“前景”状态时,我能够处理notification.title和notification.message并在应用程序的警报中显示(通过,PushNotification.configure的onNotification)。当应用程序处于“后台”状态时,我能够收到通知,当我单击它时,该应用程序就会打开或进入前台。在这里,我想获取要显示的相同的notification.title和notification.message,但在通知JSON中看不到这些字段(notification.data也为空)。以下是PushNotification.configure的onNotification中的代码:
onNotification: function (notification) {
console.log('NOTIFICATION:',JSON.stringify(notification));
if (notification.foreground) {
if(notification.userInteraction) {
Alert.alert("Title:" + notification.title + " Message:" + notification.message);
} else {
PushNotification.localNotification({
id: notification.id,autoCancel: true,title: notification.title,message: notification.message,vibrate: true,vibration: 300,playSound: true,soundName: 'default',});
PushNotification.cancelLocalNotifications({id: notification.id});
}
} else {
console.log("notification.data:",JSON.stringify(notification.data));
if(notification.userInteraction) {
console.log("Showing modal with notification details...");
}
}
},
感谢您抽出宝贵时间对此进行研究。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。