如何确定用户是否安装了iOS应用程序?

如何确定iOS设备的用户是否安装了特定的应用程序? 如果我知道应用程序的名称,我可以使用canOpenURL莫名其妙?

如果应用程序支持自定义urlscheme,则可以检查UIApplication -canOpenURL: 这只会告诉你,一个应用程序能够打开该URLscheme是可用的,不一定是哪个应用程序。 没有公开的机制来检查用户在其设备上安装了哪些其他应用程序。

如果您同时控制这两个应用程序,则可能还会使用共享钥匙串或粘贴板更详细地进行通信。

你也可以这样检查:

 BOOL temp = [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"yourAppURL://"]];   if(!temp) { NSLog(@"INVALID URL"); //Or alert or anything you want to do here } 

为迅速的用户

  let urlPath: String = "fb://www.facebook.com" let url: NSURL = NSURL(string: urlPath)! let isInstalled = UIApplication.sharedApplication().canOpenURL(url) if isInstalled { print("Installed") }else{ print("Not installed") } 

Facebook在内部使用这个https://github.com/facebook/facebook-ios-sdk/blob/master/FBSDKCoreKit/FBSDKCoreKit/Internal/FBSDKInternalUtility.m ,你可以做同样的事情

 #define FBSDK_CANOPENURL_FACEBOOK @"fbauth2" + (BOOL)isFacebookAppInstalled { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ [FBSDKInternalUtility checkRegisteredCanOpenURLScheme:FBSDK_CANOPENURL_FACEBOOK]; }); NSURLComponents *components = [[NSURLComponents alloc] init]; components.scheme = FBSDK_CANOPENURL_FACEBOOK; components.path = @"/"; return [[UIApplication sharedApplication] canOpenURL:components.URL]; } 

代码在Swift 3中

 static func isFacebookAppInstalled() -> Bool { let schemes = ["fbauth2", "fbapi", "fb"] let schemeUrls = schemes.flatMap({ URL(string: "\($0)://") }) return !schemeUrls.filter({ UIApplication.shared.canOpenURL($0) }).isEmpty }