Ad

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.

Ad

Answer

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.

Ad
source: stackoverflow.com
Ad