Swift - "sharedApplication unavailable". Use views controller solutions instead

I open the external URL in my Swift application using the line:

UIApplication.sharedApplication().openURL(url) 

This worked fine until I added Realm to my project through CocoaPods. At that moment, he started giving me two compilation errors:

'sharedApplication ()' is not available: use a controller based on the presentation of the solution, where appropriate.

'openURL' is not available

These errors indicate that the API is not available for application extensions, but my code is in a regular application and not in an extension. Why does adding Realm cause the compiler to think about it in the application extension?

+8
ios swift swift2 realm
source share
3 answers

You cannot use sharedApplication from an application extension.

But note that the apple documentation says:

IMPORTANT

Apple allows any widget today to use openURL: completeHandler: a method to open its own widgets containing the application.

ExtensionOverview.

+4
source share

This is a problem that may occur when adding Realm to a project that uses a version of CocoaPods prior to v0.39. To fix this, upgrade to the latest version of CocoaPods using:

 sudo gem install cocoapods 

This issue occurs because of CocoaPods Problem No. 3906 , as a result of which some Realm configuration settings apply to your targets. One of the options that Realm provides is "Allow only application extension APIs," so you see this specific error.

+1
source share

I still have the same problem, even with CP v1.8.3.

Quickly fix this by selecting the intruder module> Build Settings> Require only API safe for application extensions > Set to None.

0
source share

All Articles