Wednesday, May 22, 2013

canOpenURL example UIApplication ios

[UIApplication canOpenURL]

Returns whether an application can open a given URL resource.
- (BOOL)canOpenURL:(NSURL *)url
A URL object that identifies a given resource. The URL’s scheme—possibly a custom scheme—identifies which application can handle the URL.
Return Value of [UIApplication canOpenURL]
NO if no application is available that will accept the URL; otherwise, returns YES.
Discussion of [UIApplication canOpenURL]
This method guarantees that that if openURL: is called, another application will be launched to handle it. It does not guarantee that the full URL is valid.
Example of [UIApplication canOpenURL]
NSString *wazeAppURL = @"waze://";
NSString *mapsAppURL = @"maps://";

BOOL canOpenURL = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:wazeAppURL]];

NSString *url = canOpenURL ? wazeAppURL : mapsAppURL;
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
Example of [UIApplication canOpenURL]
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"cydia://"]])
    NSLog(@"cydia installed");
    NSLog(@"cydia not installed");
Example of [UIApplication canOpenURL]
BOOL canOpenURL = [[UIApplication sharedApplication] 
                       canOpenURL:[NSURL URLWithString:@"app://"]];
if ( canOpenURL ) [[UIApplication sharedApplication]                        openURL:[NSURL URLWithString:url]];