目前,当应用程序运行时打开推送通知时,它将导航到正确的内容场景。然而,当应用程序关闭,并且用户打开推送通知时,它将只打开应用程序而不导航到相关的内容场景。我认为问题与onNotification函数有关,与checkLogin函数同时触发。我想以某种方式等到checkLogin完成并继续运行onNotification。我感谢任何人的帮助。
// When receiving an incoming notification (iOS/Android)
onNotification: async function (notification) {
//for iOS the data is nested, for Android the data is attached directly to the object
let data = (Platform.OS === 'ios') ? notification.data : notification;
let id = data._id;
let channelId = data.channel;
let message = data.message;
Logger.info('Notification Received', message);
if (isLoggedIn()) {
// Check if the logged in user is the one who received the message
let content = ModelCache.getContent(id);
Navigation.goContent(content);
}
},
当应用程序启动时,此代码块位于索引文件中。
componentWillMount() {
this.checkLogin();
}
async checkLogin() {
let user = await Data.getStoredUser();
this.setState({
isUserChecked: true,
initialRoute: user ? Navigation.MAIN_SCENE : Navigation.LANDING_SCENE
});
}
答案 0 :(得分:1)
由于它是javascript,因此不太可能同时发生一件事,因此可能意味着在onNotification
函数之前调用了checkLogin
。也许一种解决方法是在onNotification
内设置一个值,checkLogin
可以引用该值并对其采取行动。