react-native – 如何在React Native with One Signal中打开通知
这是我的代码,如何在点击通知中的通知或按钮时将用户导航到所需的屏幕.
componentWillMount() { OneSignal.addEventListener('received',this.onReceived); OneSignal.addEventListener('opened',this.onOpened); OneSignal.addEventListener('registered',this.onRegistered); OneSignal.addEventListener('ids',this.onIds); OneSignal.inFocusDisplaying(2); OneSignal.requestPermissions({ alert: true,badge: true,sound: true }); } componentWillUnmount() { this.isUnmounted = true; OneSignal.removeEventListener('received',this.onReceived); OneSignal.removeEventListener('opened',this.onOpened); OneSignal.removeEventListener('registered',this.onRegistered); OneSignal.removeEventListener('ids',this.onIds); } onReceived(notification) { console.log("Notification received: ",notification); } onOpened(openResult) { // HERE I WANT TO NAVIGATE TO ANOTHER SCREEN INSTEAD OF HOME SCREEN this.isNotification = true; let data = openResult.notification.payload.additionalData; let inFocus = openResult.notification.isAppInFocus; console.log('Message: ',openResult.notification.payload.body); console.log('Data: ',openResult.notification.payload.additionalData); console.log('isActive: ',openResult.notification.isAppInFocus); console.log('openResult: ',openResult); } onRegistered(notifData) { console.log("Device had been registered for push notifications!",notifData); } onIds(device) { try { AsyncStorage.setItem("@SC:deviceInfo",JSON.stringify(device)); } catch (error) { console.log(error); } } 有没有人知道所有这些,React Native OneSignal React Navigation Redux.请帮忙!
为了达到理想的行为,你可以做几件事.您可以手动检查路由器的通知和状态,如果需要将用户重定向到屏幕,或者您可以使用
Deep Linking功能.
要使用深度链接,请在发送时将
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |