如何在ios上的react-native-push-notification中向通知对象添加其他数据?

时间:2018-02-16 13:23:56

标签: ios react-native push-notification apple-push-notifications react-native-push-notification

知道如何在ios上的react- native-push-notification 中向通知对象添加其他数据吗?

目前我将此作为正文发送:

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

我无法弄清楚如何添加通知警报中不会显示的其他数据(例如用户ID),以便在用户点击通知时将用户重定向到正确的视图。

1 个答案:

答案 0 :(得分:3)

您可以向正文添加另一个属性以传递其他数据:

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

有关详细信息,请参阅Apple docs中的Creating the Remote Notification Payload