I have a Swift application for iOS 8 with an application component, an extension component, and a wireframe that contains many shared resources - shared view controllers, shared resources, etc. At some point I want to call
UIApplication.sharedApplication().openURL(someURL)
But if I do this when the "Allow application extension APIs" checkbox is selected, this will lead to errors because UIApplication.sharedApplication () is not available in extensions. If I uncheck this box, I get a warning that it might not be safe to include the framework in the extension, and I am worried that it might lead to a rejection when it comes to sending time.
If this code was used only in extensions, I would use something like:
extensionContext.openURL(someURL, completionHandler: nil)
... but this does not work in standalone applications, only in extensions.
It is trivial to modify my code to make sure the string is UIApplication.sharedApplication (). openURL () is never called by the extension, and the extensionContext.openURL () line is never called by the application, but this does not fix the error - just the presence of UIApplication.sharedApplication () in the extension API structure causes an error.
So, before I start looking for hacks, is there a clean solution that allows me to call openURL and take the right action without causing compilation errors?
Thanks in advance!
source
share