2010-09-27 143 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"]]; 
    } 
} 
相關問題