You need to install LSApplicationQueriesSchemes in plist, if not set:
how
<key>LSApplicationQueriesSchemes</key> <array> <string>urlscheme1</string> <string>urlscheme2</string> </array>
Also note that openURL (_ :) is deprecated in iOS 10.
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 :).
New method in iOS 10 :
- (void)openURL:(NSURL*)url options:(NSDictionary<NSString *, id> *)options completionHandler:(void (^ __nullable)(BOOL success))completion
Options:
URL to open
Dictionary of options (see below for valid entries). Use an empty dictionary for the same behavior as openURL:
a call completion handler in the main queue with success. Nullable if you are not interested in status.
how
UIApplication *application = [UIApplication sharedApplication]; [application openURL:URL options:@{} completionHandler:nil];
Example:
NSString *scheme=[NSString stringWithFormat: @"whatsapp://send?abid=%@&text=WelcomeToChatBought",[abidArray objectAtIndex:buttonclicked.tag-1000]]]; UIApplication *application = [UIApplication sharedApplication]; NSURL *URL = [NSURL URLWithString:scheme]; 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); }
More details here:
http://useyourloaf.com/blog/openurl-deprecated-in-ios10/
Edit: (code based on iOS version)
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 = [[UIApplication sharedApplication] canOpenURL:URL]; if(can){ [[UIApplication sharedApplication] openURL:URL]; } }
source share