我正在从服务器收到通知。收到通知后,当我点击它时,同样的通知又来了。更多我点击它更多的通知来了。
我的问题是我在上面的代码中是否遵循了正确的方法?如果没有,请建议我正确的。如何处理通知的点击?因此,我可以在其点击时显示特定 View 。
我正在使用以下链接 https://github.com/zo0r/react-native-push-notification
提前致谢:)
PushNotification.configure({
onNotification: function (notification) {
console.log('NOTIFICATION:', notification)
PushNotification.localNotification({
largeIcon: "ic_launcher",
title: notification.title,
message: notification.message,
});
},
senderID: "my sender ID",
popInitialNotification: true,
requestPermissions: true,
});
最佳答案
我尝试了以下方法来解决这个问题
PushNotification.configure({
onNotification: function (notification) {
console.log('NOTIFICATION:', notification)
const clicked = notification.userInteraction;
if (clicked) {
ToastAndroid.show(notification.message,ToastAndroid.CENTER);
} else {
PushNotification.localNotification({
largeIcon: "ic_launcher",
title: "Test",
//message: JSON.stringify(xyz.notificationResponse.bookingId),
});
}
ToastAndroid.show(notification.message,ToastAndroid.CENTER);
},
senderID: "your sender id",
popInitialNotification: true,
requestPermissions: true,
});
关于android - React Native PushNotification onNotification 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44327125/