New method in iOS 10:
- (void)openURL:(NSURL*)url options:(NSDictionary<NSString *, id> *)options completionHandler:(void (^ __nullable)(BOOL success))completion
Read the Doc here:
https://developer.apple.com/library/prerelease/content/releasenotes/General/WhatsNewIniOS/Articles/iOS10.html
The new UIApplication method is openURL: options: completeHandler:, which runs asynchronously and calls the specified completion handler in the main queue (this method replaces openURL :).
For below iOS 10:
[[UIApplication sharedApplication] openURL:URL];
You can use the code below:
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]; } }
You also need to install LSApplicationQueriesSchemes in plist, if not set:
how
<key>LSApplicationQueriesSchemes</key> <array> <string>urlscheme1</string> <string>urlscheme2</string> </array>
Also read the answer here: fooobar.com/questions/1258250 / ...
source share