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

时间:2011-08-24 01:09:42

标签: ios

如何确定iOS设备的用户是否安装了特定的应用程序?如果我知道应用程序的名称可以以某种方式使用canOpenURL吗?

4 个答案:

答案 0 :(得分:11)

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

如果你控制这两个应用程序,你也可以使用共享的钥匙串或粘贴板来更详细地进行通信。

答案 1 :(得分:8)

你也可以这样检查:

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

答案 2 :(得分:0)

对于快速用户

     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")
    }

答案 3 :(得分:0)

Facebook在内部使用此https://angular.io/docs/ts/latest/api/core/index/Component-decorator.html,您可以执行相同的操作

#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
 }
相关问题