paco valero paco valero - 1 month ago 76
Objective-C Question

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!

Answer

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)
}
Comments