如何为本机应用程序设置 URL 方案/链接 [英] How to set a URL scheme/link for a react-native app

查看:98
本文介绍了如何为本机应用程序设置 URL 方案/链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 oauth 授予对 react-native 应用程序的访问权限,用于 spotify web api.我知道我需要使用 linking 来处理传出/传入访问到我的应用程序,但我在哪里可以指定我的 react-native 应用程序的 URI 方案,以便操作系统知道使用令牌返回我的应用程序?

I wanted to grant access to a react-native app using oauth for the spotify web api. I know I need to use linking to handle outgoing/incoming access to my app, but where can I specify the URI scheme of my react-native app so that the OS knows to go back to my app with the token?

推荐答案

要指定 URL 方案,请修改您的 AndroidManifest.xml 并在 react native 提供的过滤器下添加一个额外的意图过滤器.更新你的方案 &你的主人,带着你的价值观.

To specify the URL scheme, modify your AndroidManifest.xml and add an additional intent-filter under the one provided by react native. Update yourscheme & yourhost with your values.

<activity
    android:name=".MainActivity"
    android:label="@string/app_name"
    android:screenOrientation="portrait"
    android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
    <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="yourscheme"
            android:host="yourhost" />
    </intent-filter>
  </activity>

这篇关于如何为本机应用程序设置 URL 方案/链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆