如何解决如何在推送通知中检测 Onpress React Native
我在我的项目中使用了 react-native-push-notification
包。当用户点击通知时。如何使用 OnNotification 函数在 android 和 ios 中检测它?这是代码
import PushNotification from "react-native-push-notification";
import PushNotificationIOS from "@react-native-community/push-notification-ios";
PushNotification.configure({
onRegister: function (token) {
console.log("TOKEN:",token);
},onNotification: function (notification) {
console.log("[onNotification] :",notification);
notification.finish(PushNotificationIOS.FetchResult.NoData);
},onAction: function (notification) {
console.log("[onAction]",notification.action);
console.log("[onAction]:",notification);
},onRegistrationError: function (err) {
console.error(err.message,err);
},permissions: {
alert: true,badge: true,sound: true,},popInitialNotification: true,requestPermissions: true,});
解决方法
您可以使用传递给 userInteraction
回调的 notification
对象参数的 onNotification
属性,如其 documentation 中所述。
这是一个例子
PushNotification.configure({
onNotification: function (notification) {
if (notification.userInteraction) {
// Handle notification click
}
notification.finish(PushNotificationIOS.FetchResult.NoData);
},});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。