React Native 深度链接在真实设备上不起作用

React Native deep linking is not working on real device

我使用uri-scheme for environment setup and testing and follow the steps from React Navigation Doc设置导航。当我通过 npx uri-scheme open myapp://do_something/some_params --{android/ios} 在模拟器上测试时,一切看起来都很好。它在应用程序处于 运行 前景、背景或关闭时起作用。但是,当我试戴 phone 时,没有任何反应。

我尝试点击电子邮件中的 link,没有任何反应。 在浏览器地址栏中,我尝试输入 uri myapp://do_something/some_params。浏览器仍在主页上,没有 'open myapp' 弹出窗口。

AndroidManifest.xml:

...
   <activity android:name=".MainActivity" android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize" android:theme="@style/Theme.App.SplashScreen">
      <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
      </intent-filter>
      <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:scheme="myapp"/>
      </intent-filter>
    </activity>
...

Info.plist:

...
        <array>
            <dict>
                <key>CFBundleURLSchemes</key>
                <array>
                    <string>myapp</string>
                </array>
            </dict>
        </array>
...

AppDelegate.m:

#import <React/RCTLinkingManager.h>

...
- (BOOL)application:(UIApplication *)application
   openURL:(NSURL *)url
   options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
  return [RCTLinkingManager application:application openURL:url options:options];
}
...

App.js:

const deepLinkingConfig = {
  prefixes: ['myapp://'],
  config: {
    screens: {
      HOME: {
        screens: {
          SOMESCREEN: 'do_something/:some_params',
        }
      }
    },
  },
}
...
<NavigationContainer linking={deepLinkingConfig}>
    ...
<NavigationContainer />
...

我找不到任何错误。

您应该创建一个包含 link 的小示例 HTML 页面,然后在您的浏览器中打开该页面。如果在浏览器中输入 link,deeplinking 不会被调用,只能通过单击 link。也并非所有应用程序(例如您的邮件客户端)都支持深度 linking。此外,您应该首先使用配置启动您的应用程序,然后给系统一点时间(最多一分钟)来注册更改。如果没有任何效果,请尝试卸载并重新安装。不幸的是,Deeplinking 有一些弱点。

在您为您的应用提供真正的 http 架构之前,它不会是可点击的

您必须配置通用链接,请参阅此处:React Native url deep linking like YouTube

iOS: https://www.raywenderlich.com/6080-universal-links-make-the-connection

Android: https://developer.android.com/training/app-links

另请查看 Firebase 动态链接:https://firebase.google.com/products/dynamic-links?gclid=EAIaIQobChMI7Nixubba9AIVxrLVCh0m4wFnEAAYASAAEgI0nfD_BwE&gclsrc=aw.ds