编辑:对造成的误解表示歉意。将您的应用配置为通过链接打开因平台而异。
IOS
首先将以下内容添加到您的Info.plist
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>testapp</string>
</array>
</dict>
</array>
如果在 Xcode 而不是文本编辑器中编辑,请在 Item 0 下创建一个名为“URL 类型”的键,创建一个名为 URL Schemes 的键并在 URL Schemes 下设置 Item 0 等于字符串 testapp(或任何链接应该是)
接下来在您的 AppDelegate.m 文件中将其添加到您上次导入的下方
#import <React/RCTLinkingManager.h>
Finally, add the following to your `AppDelegate.m` file under `@implementation AppDelegate`
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
return [RCTLinkingManager application:application openURL:url
sourceApplication:sourceApplication annotation:annotation];
}
现在在地址栏中输入testapp:// 将打开您的应用
很遗憾,通过 iMessage 使此链接可点击将不工作。您最好的选择是使用以下脚本托管一个简单的网页:
<script>
window.location = "testapp://"
</script>
然后你可以在www.testapp.com 托管它,当用户导航到那里时它会打开你的应用程序。
安卓
将intent-filter 添加到您的AndroidManifest.xml 文件中
<intent-filter android:label="filter_react_native">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" android:host="testapp" /> // A
</intent-filter>
就是这样!现在http://testapp 将在 Android 上打开您的应用并可以点击。