【问题标题】:Navigate to specific screen when clicked on notification?单击通知时导航到特定屏幕?
【发布时间】:2018-02-27 13:46:29
【问题描述】:

我正在使用 react-native-fcm 进行通知并成功接收通知。我的问题是当我点击该通知时,它必须导航到特定屏幕。

我有一个带有主页和警报的堆栈导航器。 我正在登录时编写我的代码,其中很多导航到警报。

FCM.on(FCMEvent.Notification, async (notif) => {
if (notificationData.message === 'New alert generated.') {

        FCM.presentLocalNotification({
            vibrate: 500,
            title: 'title',
            priority: "high",
            show_in_foreground: true,
            group: 'test',
            large_icon: "ic_launcher",
            icon: "ic_launcher",
        });
    }
}

这里我使用 presentLocalNotification() 来显示通知。我应该在哪里使用this.props.navigation.navigate('alerts');

【问题讨论】:

    标签: javascript reactjs react-native react-navigation react-native-fcm


    【解决方案1】:
    FCM.on(FCMEvent.Notification, async (notif) => {
     if(notif){
      if(notif.opened_from_tray && notif.local_notification) {
         // Handle navigation here
         this.props.navigation.navigate('alerts');
       } else {
         FCM.presentLocalNotification({
                vibrate: 500,
                title: 'title',
                priority: "high",
                show_in_foreground: true,
                group: 'test',
                large_icon: "ic_launcher",
                icon: "ic_launcher",
            });
       }
     }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-02
      • 2019-12-01
      • 1970-01-01
      相关资源
      最近更新 更多