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功能.

要使用深度链接,请在发送时将url参数附加到通知中.要将用户定向到应用中的正确屏幕,您可以使用react-navigation deep linking功能.

From One Signal Documentation

url string The URL to open in the browser when a user clicks on the
notification. Example: 07003

Note: iOS needs https or updated NSAppTransportSecurity in plist

From React Navigation Documentation

Deep Linking

In this guide we will set up our app to handle external URIs. Let’s start with the SimpleApp that we created in the
07004. In this example,we want a URI like
mychat://chat/Taylor to open our app and link straight into Taylor’s chat page.

相关文章

一、前言 在组件方面react和Vue一样的,核心思想玩的就是组件...
前言: 前段时间学习完react后,刚好就接到公司一个react项目...
前言: 最近收到组长通知我们项目组后面新开的项目准备统一技...
react 中的高阶组件主要是对于 hooks 之前的类组件来说的,如...
我们上一节了解了组件的更新机制,但是只是停留在表层上,例...
我们上一节了解了 react 的虚拟 dom 的格式,如何把虚拟 dom...