New method in iOS 10:
- (void)openURL:(NSURL*)url options:(NSDictionary<NSString *, id> *)options
completionHandler:(void (^ __nullable)(BOOL success))completion
Read Doc here:
https://developer.apple.com/library/prerelease/content/releasenotes/General/WhatsNewIniOS/Articles/iOS10.html
The new UIApplication method openURL:options:completionHandler:, which
is executed asynchronously and calls the specified completion handler
on the main queue (this method replaces openURL:).
For below iOS 10:
[[UIApplication sharedApplication] openURL:URL];//URL is NSURL
You can use below code:
UIApplication *application = [UIApplication sharedApplication];
NSURL *URL = [NSURL URLWithString:strUrl];
if([[UIDevice currentDevice].systemVersion floatValue] >= 10.0){
if ([application respondsToSelector:@selector(openURL:options:completionHandler:)]) {
[application openURL:URL options:@{}
completionHandler:^(BOOL success) {
NSLog(@"Open %@: %d",scheme,success);
}];
} else {
BOOL success = [application openURL:URL];
NSLog(@"Open %@: %d",scheme,success);
}
}
else{
bool can = [application canOpenURL:URL];
if(can){
[application openURL:URL];
}
}
Also need to set LSApplicationQueriesSchemes
in plist if not set:
Like,
<key>LSApplicationQueriesSchemes</key>
<array>
<string>urlscheme1</string>
<string>urlscheme2</string>
</array>
Also read answer here: https://stackoverflow.com/a/40042291/5575752