SundayMonday
SundayMonday

Reputation: 19727

How can I determine if a user has an iOS app installed?

How can I determine if the user of an iOS device has a specific application installed? If I know the name of the application can I use canOpenURL somehow?

Upvotes: 11

Views: 10907

Answers (4)

onmyway133
onmyway133

Reputation: 48065

Facebook uses this https://github.com/facebook/facebook-ios-sdk/blob/master/FBSDKCoreKit/FBSDKCoreKit/Internal/FBSDKInternalUtility.m internally, you can do the same

#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];
}

Code in 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
 }

Upvotes: 0

AyAz
AyAz

Reputation: 2057

for swift users

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

Upvotes: 1

Developer
Developer

Reputation: 6465

You can check in this way as well:

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

Upvotes: 8

Jonah
Jonah

Reputation: 17958

If the application supports a custom url scheme you can check UIApplication -canOpenURL:. That will tell you only that an application able to open that url scheme is available, not necessarily which application that is. There's no publicly available mechanism to inspect what other apps a user has installed on their device.

If you control both apps you might also use a shared keychain or pasteboard to communicate between them in more detail.

Upvotes: 12

Related Questions