我该如何在我的iOS应用程序中查找另一个应用程序的scheme并深度链接到它?
更具体地说,我想在特定条件下(由我的代码设置)深度链接到Testflight应用程序。 我假设用户已安装了Testflight(这可能是一个错误的假设,但我们可以接受这个假设)。
我知道在Android上,您可以查询应用程序并发送意图来深度链接到其他人的应用程序。 在iOS上等效的方法是什么?
我该如何在我的iOS应用程序中查找另一个应用程序的scheme并深度链接到它?
更具体地说,我想在特定条件下(由我的代码设置)深度链接到Testflight应用程序。 我假设用户已安装了Testflight(这可能是一个错误的假设,但我们可以接受这个假设)。
我知道在Android上,您可以查询应用程序并发送意图来深度链接到其他人的应用程序。 在iOS上等效的方法是什么?
你需要做两件事情。首先,检查是否安装了TestFlight。然后创建一个新链接到你的应用程序。
NSURL *customAppURL = [NSURL URLWithString:@"itms-beta://"];
if ([[UIApplication sharedApplication] canOpenURL:customAppURL]) {
// TestFlight is installed
// Special link that includes the app's Apple ID
customAppURL = [NSURL URLWithString:@"https://beta.itunes.apple.com/v1/app/978489855"];
[[UIApplication sharedApplication] openURL:customAppURL];
}
这个特殊的URL https://beta.itunes.apple.com
将会在TestFlight中直接打开。
最后,如果你使用的是iOS 9或之后的版本,需要对你的Info.plist进行修改才能让canOpenURL:
方法正常工作。
如果你的应用程序链接于iOS 9.0或之后的版本,你必须声明要传递给此方法的URL schemes。你需要在Xcode项目的Info.plist文件中使用LSApplicationQueriesSchemes数组来做到这一点。对于每个你想要你的应用程序使用此方法的URL scheme,请将其作为字符串添加到此数组中。
<key>LSApplicationQueriesSchemes</key>
<array>
<string>itms-beta</string>
</array>
https://beta.itunes.apple.com/v1/app/
加上应用程序的ID。请注意,这并没有在任何地方记录下来,随时可能会更改。 - piccianoitms-beta://beta.itunes.apple.com/v1/app/978489855
- dberwick从查看plist文件中,TestFlight的URL模式为"itms-beta://"。目前我还无法实现深度链接,我已经尝试传递苹果ID,并在前缀中加上appleid =和问号,但都未成功。接下来我将尝试使用bundle ID。
要在用户设备上打开TestFlight应用程序,您可以使用以下方法:
NSURL *customAppURL = [NSURL URLWithString:@"itms-beta://"];
if ([[UIApplication sharedApplication] canOpenURL:customAppURL]) {
[[UIApplication sharedApplication] openURL:customAppURL];
}
Swift 3/4解答:
if let customAppURL = URL(string: "itms-beta://"){
if(UIApplication.shared.canOpenURL(customAppURL)){
UIApplication.shared.open(customAppURL, options: [:], completionHandler: nil)
}
}
http://wiki.akosma.com/IPhone_URL_Schemes - 这两个网站都有很好的URL方案列表
NSURL *customAppURL = [NSURL URLWithString:@"urlscheme://"];
//Eg: NSURL *whatsappURL = [NSURL URLWithString:@"whatsapp://send?text=Hello%20World!"];
if ([[UIApplication sharedApplication] canOpenURL:whatsAppURL]) {
[[UIApplication sharedApplication] openURL:whatsAppURL]]];
}
另一种调用任一应用程序的方式:
- (IBAction)go:(id)sender {
NSString *cnnAppURL = @"cnn://";
NSString *mapsAppURL = @"maps://";
BOOL canOpenURL = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:cnnAppURL]];
NSString *url = canOpenURL ? cnnAppURL : mapsAppURL;
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
}
canOpenURL
的 URL schemes
的博客文章,该内容与新的安全问题和解决方案有关。引用内容如下:canOpenURL
函数相关的问题。最佳响应的Swift更新。
我想补充说明的是,它仍然适用于iOS 16。
并且即使没有安装TestFlight,打开URL也是相关的(它将在Safari中打开,并建议安装TestFlight)。
// Special scheme specific to TestFlight
let presenceCheck = URL(string: "itms-beta://")!
// Special link that includes the app's ID
let deepLink = URL(string: "https://beta.itunes.apple.com/v1/app/<app-id>")!
let app = UIApplication.shared
if app.canOpenURL(presenceCheck) {
app.open(deepLink)
}
Linking.canOpenURL(config.testFlightUrl) .then(supported => { if (!supported) { console.log("无法打开链接"); } else { return Linking.openURL(config.testFlightUrl); } }) .catch(err => console.error("无法打开链接", err));
- Sriram C G