【问题标题】:Deep Linking does nothing on android React Native深度链接在 android React Native 上没有任何作用
【发布时间】:2021-05-26 20:55:10
【问题描述】:

我正在尝试在 React Native 中实现深度链接功能,我遵循了 React Native 的官方文档,也遵循了 React Navigation 的文档。我已经更改了我的 AndroidManifest.xml 文件并根据文档添加了意图过滤器,如下所示:

    <intent-filter>
       <action android:name="android.intent.action.VIEW"/>
       <category android:name="android.intent.category.DEFAULT"/>
       <category android:name="android.intent.category.BROWSABLE"/>
      <data android:host="app" android:scheme="demo"/>
</intent-filter>

还将 android:lunchMode 更改为 android:launchMode="singleTask"

当我使用npx react-native android 安装应用程序并且应用程序成功安装在用户设备上时。 之后我运行 adb 命令来检查深度链接,我得到以下响应:

$ adb shell am start -W -a android.intent.action.VIEW -d "demo://app/chat/123" com.rndemo
Starting: Intent { act=android.intent.action.VIEW dat=app://whatsupp/chat/123 pkg=com.whatsupfire }
Warning: Activity not started, intent has been delivered to currently running top-most instance.
Status: ok
Activity: com.rndemo/.MainActivity
ThisTime: 0
TotalTime: 0
WaitTime: 19
Complete

这是我的链接配置:

const config = {
  screens: {
    Chat: {
      screen: {
        ChatStack: {
          path: 'chat/:id',
          parse: {
            toId: (id) => `${id}`,
          },
        },
      },
    },
  },
};

const linking = {
  prefixes: ['demo://', 'demo://app'],
  config: config,
};

我正在使用 React Navigation V5,我正在 NavigatorContainer 中的 App.js 中使用链接,这里要提到的重要一点是,我正在使用 React Navigation 的官方文档使用身份验证流程,并且聊天嵌套在导航器中,但我也尝试访问 demo://app 并且 adb shell 返回与上述相同的响应。

【问题讨论】:

    标签: react-native react-navigation deep-linking react-navigation-v5 react-native-deep-linking


    【解决方案1】:

    为 NavigationContainer 添加链接道具:

    <NavigationContainer linking={linking} >
    

    【讨论】:

    • 我已经添加了,我以某种方式解决了问题,但是在使用 React Native Linking.openURL 打开链接时遇到了另一个问题
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-25
    • 1970-01-01
    相关资源
    最近更新 更多