2010-09-27 145 views
15

我处于这种情况下,必须显示一个说明“打开myApp”(如果myApp安装在设备上)或“下载myApp”(如果myApp是没有安装在设备上)在iphone应用程序。为此,我需要检测设备上是否安装了应用程序(带有已知的自定义URL)。我怎样才能做到这一点?提前致谢。 2014以编程方式检测应用程序是否安装在iPhone上

回答

32

修订版1月8日 - 3事情可以做,

其实我不得不再次做到这一点的客户端。他们希望用户能够从主应用程序打开他们的第二个应用程序,如果它已经安装。

这是我的发现。使用canOpenURL方法来检查是否安装了应用的或/和然后使用openURL方法

  1. 打开安装iOS设备
  2. 上的应用程序将用户带到应用商店直接指向他们的应用程序/你开发的应用程式列表
  3. 带他们到一个网站,而不是

提供的所有代码样本,每个场景

//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"]]; 

    } 
} 

选择一个选项,我只是宠坏你的选择。选择一个适合您的要求。 在我的情况下,我不得不在程序的不同区域使用全部三个选项。

+0

plist中没有在iOS中4找到你知道哪里有它被移动至? – samwize 2011-02-04 08:00:04

+0

嗨,对于迟到的回复感到抱歉。没问题。该文件位于'/ private/var/mobile/Library/Caches /'文件夹中。希望有所帮助。干杯 – Pavan 2011-04-30 05:43:33

+0

这是switch-case 2的路径。但是找不到该文件(在iOS 4.3上)。 – samwize 2011-05-03 06:17:51

19

如果您的应用程序的URL方案 “的myapp:”,然后

BOOL myAppInstalled = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"myapp:"]]; 

(需要iOS 3.0)。

+0

更简单!谢谢! – bkbeachlabs 2013-02-04 01:08:57

+0

@bkbeachlabs比较简单多少? – Pavan 2014-05-29 23:31:53

+0

我一定是指另一个答案的早期编辑。很久很久以前,所以我不记得了! – bkbeachlabs 2014-05-30 05:34:11

0

您可以在需要的任何页面的头部添加一个简单的meta标签这个应用程序嗅探。

欲了解更多信息,请浏览:

http://developer.apple.com/library/ios/#documentation/AppleApplications/Reference/SafariWebContent/PromotingAppswithAppBanners/PromotingAppswithAppBanners.html

+1

也许,在您的帖子中总结您网址的内容可以帮助用户更多地发布链接。除此之外,你的第一篇文章做得很好:-)。 – 2013-03-26 19:20:01

5

要检查应用程序是安装在设备或不

1)在info.plist中添加LSApplicationQueriesSchemes如下面的例子

enter image description here

2)和URL类型

enter image description here

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"]]; 
    } 
} 
相关问题