简体   繁体   English

如何为本机应用程序设置URL方案/链接

[英]How to set a URL scheme/link for a react-native app

I wanted to grant access to a react-native app using oauth for the spotify web api. 我想使用Spotify Web API的oauth授予对本机应用程序的访问权限。 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? 我知道我需要使用链接来处理对我的应用程序的传出/传入访问,但是在哪里可以指定我的本机应用程序的URI方案,以便操作系统知道使用令牌返回我的应用程序?

To specify the URL scheme, modify your AndroidManifest.xml and add an additional intent-filter under the one provided by react native. 要指定URL方案,请修改您的AndroidManifest.xml并在react native提供的内容下添加一个额外的intent过滤器。 Update yourscheme & yourhost with your values. 用您的价值观更新yourschemeyourhost

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

Linking is different for each platform. 每个平台的链接都不同。 For a cross platform approach I recommend to look into: http://applinks.org 对于跨平台方法,我建议您研究一下: http : //applinks.org

See this link for instructions how to set this up on iOS and Android: 请参阅此链接以获取有关如何在iOS和Android上进行设置的说明:

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

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