以编程方式检测 iPhone 上是否安装了应用程序
-
25-09-2019 - |
题
我处于这种情况,我必须在 iPhone 应用程序中显示一个按钮,其中显示“打开 myApp”(如果设备上安装了 myApp)或“下载 myApp”(如果设备上未安装 myApp)。为此,我需要检测设备上是否安装了应用程序(具有已知的自定义 URL)。我怎样才能做到这一点?提前致谢。
解决方案
2014 年 1 月 8 日更新 - 您可以做的 3 件事
事实上我不得不再次为客户做这件事。他们希望用户能够从主应用程序打开第二个应用程序(如果已安装)。
这是我的发现。使用 canOpenURL
检查应用程序是否已安装或/然后使用的方法 openURL
方法
- 打开iOS设备上安装的应用程序
- 将用户带到应用程序商店,直接将他们指向应用程序/您的开发者应用程序列表
- 将他们带到网站
每个场景的所有代码示例均可用
//Find out if the application has been installed on the iOS device
- (BOOL)isMyAppInstalled {
return [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"nameOfMyApp:"]];
}
- (IBAction)openOrDownloadApp {
//This will return true if the app is installed on the iOS device
if ([self myAppIsInstalled]){
//Opens the application
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"nameOfMyApp:"]];
}
else { //App is not installed so do one of following:
//1. Take the user to the apple store so they can download the app
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"itms://itunes.com/apps/nameOfMyApp"]];
//OR
//2. Take the user to a list of applications from a developer
//or company exclude all punctuation and space characters.
//for example 'Pavan's Apps'
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"itms://itunes.com/apps/PavansApps"]];
//OR
//3. Take your users to a website instead, with maybe instructions/information
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.pavan.com/WhyTheHellDidTheAppNotOpen_what_now.html"]];
}
}
选择一个选项,我只是用选择宠坏了你。选择一款适合您的要求的产品。就我而言,我必须在程序的不同区域使用所有三个选项。
其他提示
如果你的应用程序的URL方案 “的myapp:”,然后
BOOL myAppInstalled = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"myapp:"]];
(需要iOS 3.0。)
要检查的应用程序是安装在设备或不强>
1)的在info.plist中添加LSApplicationQueriesSchemes如下面的例子强>
2)和在URL类型
3)我们检查应用程序是安装或不
- (IBAction)openAppPressed:(UIButton *)sender {
NSString *urlString = @"XYZAPP://";
NSURL *url = [NSURL URLWithString:urlString];
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url];
}
else {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"itunes link for download app"]];
}
}
您可以在需要这个程序嗅探。
任何页面头部加一个简单的meta标签有关更多信息,请点击这里:
不隶属于 StackOverflow