我已经创建了react原生应用程序并添加了Linking。当我在浏览器中打开url时,它运行良好testapp://params.现在我想将此链接共享到其他应用程序。所以我使用react原生共享库来共享这个。但这个库只是将字符串显示为文本,但不可点击。我如何让这个文本可以点击,这样当用户点击该链接时,它就会打开我的应用程序。
let shareOptions = {
title: "React Native",
message: "Hola mundo",
url: "testapp://", //Here this should be clickable
subject: "Share Link" // for email
};
Share.open(shareOptions);
有谁能帮我吗?
IOS
首先将以下内容添加到您的Info.plist
中
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>testapp</string>
</array>
</dict>
</array>
如果在Xcode而不是文本编辑器中进行编辑,则创建一个名为"的键;URL类型";,在Item 0
下创建一个名为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
上托管它,当用户导航到那里时,它会打开你的应用程序。
Android
将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上打开您的应用程序并可点击。