【发布时间】:2018-06-12 19:48:10
【问题描述】:
当用户单击或按下通知时,我希望打开特定屏幕。我经历了各种 github 问题和堆栈溢出问题和答案,但是似乎没有一个答案或选择的方式来解决这个问题。
最初我使用 PushController 类来处理 onNotification 函数,但是我没有将 configure 和 onNotification 函数移动到组件中,并安装在创建本地通知的组件中。
this.props.navigation.navigate('RouteName');
不起作用。它说this.props.navigation 或this.props.navigation.navigate 是未定义的。
PushNotification.
onNotification(notification) {
console.log('onNotification')
console.log( notification );
this.props.navigation.navigate('RegisterRoute');
},
});
从通知路由或导航到所选屏幕的正确方法是什么。我在 react-native-push-notification 问题和文档中找不到直接答案。
编辑: 此代码可以在我调用/发出本地通知的类中找到。 通知被触发和调用,当单击通知或 onNotification 时,我想导航或路由到另一个屏幕。
组件内部确实挂载了。
PushNotification.configure({
onNotification(notification) {
console.log('onNotification')
console.log( notification );
this.props.navigation.navigate('ChosenScreen');
},
});
调用并创建本地通知的函数
function sendNotification(title, pushMessage){
PushNotification.localNotification({
message: pushMessage,
title: title,
userInteraction: true,
alertAction: 'default',// (optional) default: view
autoCancel: true,
largeIcon: "logo",
smallIcon: "logo",
vibrate: true,
vibration: 300,
alertAction: 'default',
userInfo: 'default'
});
}
【问题讨论】:
-
你能添加更多代码吗,目前还不清楚你的代码中发生了什么。
-
好的。我马上添加。
-
你的问题是关于 react-navigation 而不是 react-native-navigation
-
你是如何让它工作的@Carrie?我收到了通知,但是当我单击它时,我的 onNotification 方法中没有任何控制台。被困了几个小时。
-
嘿@3iL 我已经发布了我的问题的解决方案。希望对您有所帮助!
标签: react-native react-native-navigation react-native-push-notification