如何在推送通知 React Native 中检测 Onpress
how to detect Onpress in Push notification React Native
-
react-native
-
react-native-android
-
react-native-ios
-
react-native-firebase
-
react-native-push-notification
我在我的项目中使用 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,
});
您可以使用传递给 onNotification
回调的 notification
对象参数的 userInteraction
属性,如他们的 documentation 中所述。
这是一个例子
PushNotification.configure({
onNotification: function (notification) {
if (notification.userInteraction) {
// Handle notification click
}
notification.finish(PushNotificationIOS.FetchResult.NoData);
},
});
react-native
react-native-android
react-native-ios
react-native-firebase
react-native-push-notification
我在我的项目中使用 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,
});
您可以使用传递给 onNotification
回调的 notification
对象参数的 userInteraction
属性,如他们的 documentation 中所述。
这是一个例子
PushNotification.configure({
onNotification: function (notification) {
if (notification.userInteraction) {
// Handle notification click
}
notification.finish(PushNotificationIOS.FetchResult.NoData);
},
});