Search code examples
iosreact-nativepush-notificationapple-push-notificationsreact-native-push-notification

How to add additional data to a notification object in react-native-push-notification on ios?


Any idea how to add additional data to a notification object in react-native-push-notification on ios?

Currently I'm sending this as the body:

body = { aps: { alert: "Text that is sent in the notification.", sound: "default", badge: 1 } }.to_json

I can't figure out how to add additional data that wouldn't be shown in the notification alert such as a user id to redirect the user to the correct view if he clicks on the notification.


Solution

  • You can add another property to the body to pass additional data :

    body = { 
        aps: {
          alert: "Text that is sent in the notification.",
          sound: "default",
          badge: 1 
        },
        userId: "6446qf45qsdg",
    }
    

    See Creating the Remote Notification Payload from apple docs for more info about this.