如何为反应本机应用程序设置URLscheme/链接

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

要指定URLscheme,请修改您的AndroidManifest.xml并在react native提供的scheme下添加一个额外的intent-filter。 用您的值更新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> 

每个平台的链接是不同的。 对于跨平台的方法,我build议查看: http : //applinks.org

请参阅此链接,了解如何在iOS和Android上进行设置: