2010-08-18 126 views
33

我正在开发一个iPhone应用程序,它将在企业中安装少量的第三方应用程序。我有关于捆绑ID的信息。有没有办法通过使用一些系统API来检查应用程序是否已经安装?目前应用程序再次安装,覆盖当前安装。我需要防止这一些如何。 (如果应用程序已安装,Apple的AppStore应用程序将禁用安装选项。)如何以编程方式检查是否安装了应用程序?

+2

可能重复的[如何检查在iPhone设备中安装的应用程序](http://stackoverflow.com/questions/3243567/how-to-check-installed-application-in-iphone-device) – 2010-08-18 14:25:58

+0

也许这个wiki会帮助你也是:http://wiki.akosma.com/IPhone_URL_Schemes 大部分url方案的问题是,如果你没有你要调用的应用程序的用户标识,你不能传递任何数据。 – 2013-10-09 19:34:42

+0

http://stackoverflow.com/questions/32643522/fbsdksharedialog-of-facebook-sdk-is-not-working-on-ios9/39159507#39159507 – TharakaNirmana 2016-08-26 06:17:30

回答

57

我认为这是不可能的,但如果应用程序注册uri方案,您可以测试。

对于facebook应用程序,URI方案是例如fb://。您可以在您的应用程序的info.plist中注册。 [UIApplication canOpenURL:url]会告诉你某个网址是否会打开。因此,测试fb://是否会打开,将显示已安装应用程序,其中已注册fb:// - 这是Facebook应用程序的一个好提示。

// check whether facebook is (likely to be) installed or not 
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"fb://"]]) { 
    // Safe to launch the facebook app 
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"fb://profile/200538917420"]]; 
} 
+0

“但如果应用程序注册uri计划,你可以测试”:可以你请稍微解释一下? – attisof 2010-08-18 12:58:59

31

下面就来测试,如果Facebook的应用程序安装

if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"fb://"]]) { 
    // Facebook app is installed 
} 
22

对于任何试图与iOS做到这9 /斯威夫特2个例子:

首先,你需要'白名单”中加入以下到您Info.plist文件的URL(安全功能 - 见Leo Natan's answer):

<key>LSApplicationQueriesSchemes</key> 
<array> 
    <string>fb</string> 
</array> 

之后,你可以向应用程序是否可用,并有注册计划:

guard UIApplication.sharedApplication().canOpenURL(NSURL(string: "fb://")!) else { 
    NSLog("No Facebook? You're a better man than I am, Charlie Brown.") 
    return 
} 
+1

它为我工作,谢谢 – 2015-10-09 07:49:48

1

当谈到社交网络时,最好检查多个方案。 (因为方案 'FB' 是过时的用于IOS9 SDK例如):

NSArray* fbSchemes = @[ 
    @"fbapi://", @"fb-messenger-api://", @"fbauth2://", @"fbshareextension://"]; 
BOOL isInstalled = false; 

for (NSString* fbScheme in fbSchemes) { 
    isInstalled = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:fbScheme]]; 
    if(isInstalled) break; 
} 

if (!isInstalled) { 
    // code 
    return; 
} 

当然Info.plist中也应包含所有必要的方案:

<key>LSApplicationQueriesSchemes</key> 
<array> 
    <string>fbapi</string> 
    <string>fb-messenger-api</string> 
    <string>fbauth2</string> 
    <string>fbshareextension</string> 
</array> 
3

夫特3.1,3.2斯威夫特,夫特4

if let urlFromStr = URL(string: "fb://") { 
    if UIApplication.shared.canOpenURL(urlFromStr) { 
     if #available(iOS 10.0, *) { 
      UIApplication.shared.open(urlFromStr, options: [:], completionHandler: nil) 
     } else { 
      UIApplication.shared.openURL(urlFromStr) 
     } 
    } 
} 

在Info.plist中添加这些:

<key>LSApplicationQueriesSchemes</key> 
<array> 
    <string>fb</string> 
</array> 
相关问题