如何在 React Native 中点击本地通知启动特定屏幕

问题描述

我目前在 react-native 中使用 this 库来安排本地通知,当我从通知中心或应用顶部点击通知时,我想将用户重定向到特定屏幕。目前 react-native-push-notification 库使用已弃用的旧 UIlocalnotification 类。

下面是我配置本地通知代码

onNotification 是当用户从 iOS 的通知中心启动应用时触发的回调方法,类似的 onAction 是 Android 的。

/**
 * To configure for local notifications
*/
 export function localnotificationConfigure() {
   PushNotification.configure({
   onNotification: async function (notification) {
     console.log('notification.data',notification.userInteraction);
    notification.finish(PushNotificationIOS.FetchResult.NoData);
   },onAction: async function (notification) {
    console.log('notification',notification.userInteraction);
   },permissions: {
   alert: true,badge: true,sound: true,},popInitialNotification: true,requestPermissions: Platform.OS === 'ios',});
 }

有什么办法可以做到这一点。是不是因为 lib 使用了不推荐使用的 UIlocalnotification 并且我无法在代码中恢复操作。任何帮助表示赞赏。

解决方法

这个 link 帮助我实现了我想要的功能。