简体   繁体   English

在反应移动应用程序上设置应用程序链接

[英]Setup app links on a react mobile application

Im actually making a mobile app and i'd to setup links to open it when you click on it.我实际上正在制作一个移动应用程序,我会设置链接以在您单击它时打开它。 I tried to setup app links but i doesn't seem to work... Here's my code:我试图设置应用程序链接,但我似乎没有工作......这是我的代码:

Manifest.xml清单.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.didierurban.testLenny">
    ...
  <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" android:screenOrientation="portrait">
    ...
      <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="https" android:host="example.net" />
      </intent-filter>
    </activity>
  </application>
</manifest>

My assetlink.json (on https://example.net/.well-known/assetlinks.json )我的assetlink.json(在https://example.net/.well-known/assetlinks.json上)

// 20210407190840
// https://lenny-girardot.fr/.well-known/assetlinks.json

[
  {
    "relation": [
      "delegate_permission/common.handle_all_urls"
    ],
    "target": {
      "namespace": "android_app",
      "package_name": "com.didierurban.testLenny",
      "sha256_cert_fingerprints": [
        "D4:DC:31:60:E9:B2:3F:2B:DF:23:33:31:49:D3:10:9F:3C:3A:6F:E6:1D:41:6E:DB:17:A3:3E:DD:1C:9C:6A:46"
      ]
    }
  }
]

app.json app.json

{
  "expo": {
    "scheme": "...",
    "name": "...",
    "slug": "...",
    "version": "1.0.0",
    "orientation": "portrait",
    "icon": "./assets/icon.png",
    "splash": {
      "image": "./assets/splash.png",
      "resizeMode": "contain",
      "backgroundColor": "#ffffff"
    },
    "updates": {
      "fallbackToCacheTimeout": 0
    },
    "assetBundlePatterns": [
      "**/*"
    ],
    "ios": {
      "supportsTablet": true,
      "bundleIdentifier": "..."
    },
    "android": {
      "adaptiveIcon": {
        "foregroundImage": "./assets/adaptive-icon.png",
        "backgroundColor": "#FFFFFF"
      },
      "package": "..."
    },
    "web": {
      "favicon": "./assets/favicon.png"
    }
  }
}

If app links are not working with react, what can i setup to make it work?如果应用程序链接无法与 React 一起使用,我可以设置什么使其正常工作? I also tried to use https://www.npmjs.com/package/node-deeplink but it seems outdated.我也尝试使用https://www.npmjs.com/package/node-deeplink但它似乎已经过时了。

Thank you谢谢

on expo, you first need to specify a scheme in your app.json .在 expo 上,您首先需要在app.json中指定scheme eg myawesomeapp .例如myawesomeapp

your manifest file should also have the same scheme like this您的清单文件也应该具有与此相同的方案

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.didierurban.testLenny">
    ...
  <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" android:screenOrientation="portrait">
    ...
      <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="myawesomeapp" />
      </intent-filter>
    </activity>
  </application>
</manifest>

on ios, add it to info.plist here在 ios 上,在此处将其添加到info.plist

<key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>myawesomeapp</string>
            </array>
        </dict>
    </array>

you can then open links to your app using the url myawesomeapp://然后,您可以使用 url myawesomeapp://打开指向您的应用程序的链接

you can also checkout this library for linking to other applications from your react native app您还可以签出此以从您的 react 本机应用程序链接到其他应用程序

For more info on deep linking in expo, checkout the docs here有关 expo 中的深度链接的更多信息,请在此处查看文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM