React-native-push-notification: ios payload lost when clicked

Created on 1 Nov 2017  路  5Comments  路  Source: zo0r/react-native-push-notification

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 {}

Stale

Most helpful comment

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.

All 5 comments

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?

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.

Was this page helpful?
0 / 5 - 0 ratings