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?
Asked
Active
Viewed 1.1k times
11

SundayMonday
- 19,147
- 29
- 100
- 154
4 Answers
12
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.

Jonah
- 17,918
- 1
- 43
- 70
8
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
}

Jacob Lukas
- 689
- 6
- 14

Developer
- 6,375
- 12
- 58
- 92
-
3The first line didn't compile for me, but this did: `BOOL temp = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"yourAppURL://"]];` – newenglander Oct 19 '12 at 11:41
-
I am sorry but what is the app URL ? is it the name of the app or something? – Coldsteel48 Dec 30 '15 at 12:25
1
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")
}

AyAz
- 2,027
- 2
- 21
- 28
0
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
}

onmyway133
- 45,645
- 31
- 257
- 263