当打开或接收到任何通知时,将调用回调onNotification
传递带有通知数据的对象。
通知对象示例:
{
foreground: false, // BOOLEAN: If the notification was received in foreground or not
userInteraction: false, // BOOLEAN: If the notification was opened by the user from the notification area or not
message: 'My Notification Message', // STRING: The notification message
data: {}, // OBJECT: The push data
}
因此,当 onNotification 被触发时,您可以获得数据对象并根据其值编写重定向逻辑。
为了更清楚,您可以在开始屏幕或主文件中使用此代码
var PushNotification = require('react-native-push-notification');
PushNotification.configure({
// (optional) Called when Token is generated (iOS and Android)
onRegister: function(token) {
console.log( 'TOKEN:', token );
},
// (required) Called when a remote or local notification is opened or received
onNotification: function(notification) {
console.log( 'NOTIFICATION:', notification );
// process the notification
}
});