单击通知时导航到特定屏幕?

问题描述 投票:0回答:1

我使用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个回答
-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",
        });
   }
 }
}
© www.soinside.com 2019 - 2024. All rights reserved.