Anybody encountered iOS payload (notification.data) is lost when a push notification is clicked? When I clicked it, the notification.data becomes an empty object {}
Because on iOS, the notification data comes from the userInfo property.
e.g:
{
message: 'test notification',
userInfo: {
myData: 'hello'
}
}
So when creating a notification, any additional data need to be in a userInfo prop and when the notification is received, notification.data will be populated with whatever is inside userInfo. So if there is no userInfo prop at the time of creating the notification, then the notification.data prop will be empty.
Hope this helps someone in the future.
Thank you so much for this @Eyesonly88! Works like a charm!
Just adding that if you're also using this for Android, you can register the notification under userInfo, but when you grab that data, you need to look under notification.data.myData, instead of notification.userInfo.myData.
@trspecht how did you get that to work on Android? Isn't userInfo Android only?
Nevermind, this worked for me https://github.com/zo0r/react-native-push-notification/issues/384
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
Because on iOS, the notification data comes from the
userInfoproperty.e.g:
So when creating a notification, any additional data need to be in a
userInfoprop and when the notification is received,notification.datawill be populated with whatever is insideuserInfo. So if there is nouserInfoprop at the time of creating the notification, then thenotification.dataprop will be empty.Hope this helps someone in the future.