Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Method openURL:options:completionHandler compatibility in objective c

I'm using the method openURL:options:completionHandler:, it turns out that in iOS 10 works fine, but I'm also interested in my app is compatible with the old iOS 9, but xcode gives me a

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

Unrecognized selector send to instance There any way make it work in iOS 9 also? Thank for the possible response!

like image 858
paco valero Avatar asked Oct 15 '16 08:10

paco valero


1 Answers

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:)

This is under Additional Framework Changes > UIKit at: https://developer.apple.com/library/prerelease/content/releasenotes/General/WhatsNewIniOS/Articles/iOS10.html

you need use it like this:-

if #available(iOS 10.0, *) {
    UIApplication.shared.open(url, options: [:], completionHandler: nil)
} else {
    UIApplication.shared.openURL(url)
}
like image 74
Annie Gupta Avatar answered Nov 15 '22 17:11

Annie Gupta