Push notification React Native:通过点击推送通知调用函数?

Push notification React Native:通过点击推送通知调用函数?,push-notification,react-native,Push Notification,React Native,因此,当用户点击传入的推送通知时,我想将用户放到特定的导航器场景中。使用的“场景”和“id”作为JSON传递到通知负载中 但我不知道如何处理这些价值观 PushNotificationIOS.addEventListener('notification', this._onNotification.bind(this)); “通知”事件 显然,当点击通知时,应用程序会出现,但一旦出现,我如何启动功能 谢谢 在index.ios.js中注册的最顶层组件中,在componentDidMount方法

因此,当用户点击传入的推送通知时,我想将用户放到特定的导航器场景中。使用的“场景”和“id”作为JSON传递到通知负载中

但我不知道如何处理这些价值观

PushNotificationIOS.addEventListener('notification', this._onNotification.bind(this));
“通知”事件

显然,当点击通知时,应用程序会出现,但一旦出现,我如何启动功能


谢谢

在index.ios.js中注册的最顶层组件中,在
componentDidMount
方法中,您可以添加侦听器,并从通知中:

导出默认类应用程序扩展组件{
componentDidMount(){
PushNotificationIOS.addEventListener('notification',this.\u onNotification.bind(this));
如果(通知){
const data=notification.getData();
如果(数据){
//做你的事
}
}
}
}
另一种解决方案是传递url,并在最顶层组件的componentDidMount方法中实现以下代码:

Linking.getInitialURL()。然后(url=>{
如果(!url){
返回null;
}
//做一些事情来决定加载哪个组件
导航器。推({
组件:您的组件,
通行证:{
//你的道具
},
});
返回null;
}).catch(()=>null);