At usage example described 'data' field of notification object: https://github.com/zo0r/react-native-push-notification#handling-notifications
But I don't see how to use it with local notifications.
Is there any possibilities to send some data with local notification?
+1 The same problem. How to send some data in local notifications for android and ios?
I have the same problem on Android.
Tried setting the notification like this:
onNotification(notification) {
const { foreground, userInteraction, message, data, ...rest } = notification;
console.log('NOTIFICATION:', notification);
if (foreground && !userInteraction) {
PushNotification.localNotification({ ...rest, data, message });
}
...
}
I have the same problem
You can use userInfo for iOS
@joaovpmamede For some reason data in localNotification params should be a json string (android).
@AlimovSV thank you so much. Got this working at last :)
Now I just need to find a way to get the notification object when the app is closed and I click on a notification.
I do get the object when I receive the push notification though.
send by
PushNotification.localNotification({
//..........
data: JSON.stringify({type: 'news', content: 'news one title'})
})
Parse by
PushNotification.configure({
onNotification: function(notification) {
let json = notification.data;
console.log(json.type);
},
});
Why is it necessary to put my data in a userInfo object for iOS? I see an empty data object when I send a local notification.
EDIT: I see that it maps userInfo to data object that can get handled by onNotification
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 30 days if no further activity occurs. Thank you for your contributions.
Most helpful comment
@joaovpmamede For some reason
datainlocalNotificationparams should be a json string (android).