【问题标题】:Setup app links on a react mobile application在反应移动应用程序上设置应用程序链接
【发布时间】:2021-07-03 13:18:39
【问题描述】:

我实际上正在制作一个移动应用程序,我会设置链接以在您单击它时打开它。 我试图设置应用程序链接,但我似乎没有工作......这是我的代码:

Manifest.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>

我的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

{
  "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"
    }
  }
}

如果应用程序链接无法与 react 一起使用,我可以设置什么来使其正常工作? 我也尝试使用https://www.npmjs.com/package/node-deeplink,但它似乎已经过时了。

谢谢

【问题讨论】:

  • 您想设置一个指向您的应用程序的链接吗?
  • 是的,我想设置一个链接: - 如果未安装应用程序,将您重定向到自定义 URL(例如商店链接) - 如果应用程序打开到正确的内容/屏幕应用已安装

标签: android reactjs react-native applinks android-app-links


【解决方案1】:

在博览会上,您首先需要在您的app.json 中指定一个scheme。例如myawesomeapp

您的清单文件也应该具有与此相同的方案

<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>

在 ios 上,将其添加到 info.plist 这里

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

然后您可以使用 URL myawesomeapp:// 打开指向您应用的链接

您还可以查看此 library 以从您的 react native 应用程序链接到其他应用程序

有关 expo 中深度链接的更多信息,请查看文档here

【讨论】:

  • 非常感谢您的帮助,但我有一个问题。如果应用程序没有安装,会发生什么?什么都没有?
  • @Lenny 如果未安装应用程序,则可以设置存储链接或任何其他替代方法,但这需要在服务器或您链接的应用程序上进行处理, node-deeplink 可以为您处理这个问题,如果您使用另一个 react-native 应用程序进行链接,您可以使用上面答案中添加的库。谢谢
  • Node-deeplink 还在工作吗?当我尝试让我的浏览器阻止重定向时casimages.com/i/210407082756807023.png.html 这是我的代码app.get('/deeplink', deeplink({ url: "demo://form/555", fallback: 'https://cupsapp.com', android_package_name: 'pkg.name', ios_store_link: 'https://itunes.apple.com/us/app/cups-unlimited-coffee/id556462755?mt=8&amp;uo=4' }) ) ,再次感谢您的帮助!
  • @Lenny 无法阅读该语言,因此无法真正找出问题所在,但它可能的 node-deeplink 已不再维护,但我相信可能还有其他免费或高级替代品那里。也欢迎你。如果它解决了您的问题,请随时接受答案
  • 好吧,它说“导航被阻止”我不能使用它,如果有人有解决方案,我会开几个小时的票,否则我会接受你的回答。跨度>
猜你喜欢
  • 1970-01-01
  • 2018-05-01
  • 1970-01-01
  • 2017-12-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多