I am opening an external URL in my Swift app using the line:
UIApplication.sharedApplication().openURL(url)
This was working fine until I added Realm to my project via CocoaPods. At that point, it started giving me the two compile errors below:
'sharedApplication()' is unavailable: Use view controller based solutions where appropriate instead.
'openURL' is unavailable
These errors indicate that the API is unavailable to Application Extensions, but my code is in a normal application, not an extension. Why would adding Realm result in the compiler thinking it's in an App Extension?
You can't use sharedApplication
from an app extension.
But note that the apple documentation states:
IMPORTANT
Apple allows any Today widget to use the openURL:completionHandler: method to open the widget’s own containing app.
ExtensionOverview.
This is an issue that can occur when adding Realm to a project that is using a version of CocoaPods prior to v0.39. To fix it, update to the latest version of CocoaPods using:
sudo gem install cocoapods
This problem is due to CocoaPods issue #3906, which results in portions of Realm's configuration settings being applied to your application's targets. One of the settings that Realm enables is "Allow app extension API only", which is why you end up seeing this particular error.
I still have the same issue, even with CP v1.8.3.
A quick fix is to select the offending pod > Build Settings > Require Only App-Extension-Safe API > Set to No.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With