OpenURL method: parameters: completion of Handler compatibility in c object

I use the openURL method: options: completeHandler :, it turns out that it works fine in iOS 10, but I'm also interested in my application compatible with old iOS 9, but xcode gives me

NSException: -[UIApplication openURL:options:completionHandler:]: 

An unrecognized selector sends an instance. Is there a way to make it work in iOS 9 too? Thanks for the possible answer!

+5
source share
2 answers

The new UIApplication openURL: options: completeHandler: method, which runs asynchronously and calls the specified completion handler in the main queue (this method replaces openURL :)

This applies to additional changes to the framework> UIKit at: https://developer.apple.com/library/prerelease/content/releasenotes/General/WhatsNewIniOS/Articles/iOS10.html

you need to use it like this: -

 if #available(iOS 10.0, *) { UIApplication.shared.open(url, options: [:], completionHandler: nil) } else { UIApplication.shared.openURL(url) } 
+10
source

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];//URL is NSURL 

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 / ...

+1
source

Source: https://habr.com/ru/post/1258247/


All Articles