问题
I just upgraded from XCode 6.4 to Xcode 7 GM and get started to change the code to be compliant with Swift 2. I could not come over the following errors.
The project is a keyboard extension and the snippet is from the containing app.
let s = "https://itunes.apple.com/"
UIApplication.sharedApplication().openURL(NSURL(string : s)!)
Error 1: 'sharedApplication()' is unavailable: Use view controller based solutions where appropriate instead.
Error 2: 'openURL' is unavailable.
This might be something to do with Xcode and AppDelegate, I might have screwed up my project.
回答1:
While I was making a framework. I faced this problem. Manually set it to NO solved my problem.
回答2:
You can't access every API from an extension. From Apple's Extension dev guide: Some APIs Are Unavailable to App Extensions
Because of its focused role in the system, an app extension is ineligible to participate in certain activities. An app extension cannot:
Access a sharedApplication object, and so cannot use any of the methods on that object
etc, etc.
回答3:
Your target may have the "Allow app extension API only" option checked.
Check your target's general settings to see if that option is enabled in Deployment Info > App Extensions.
回答4:
Swift 3.0
In my case I had this message inside a Widget (that's an extension), the code was a copy/paste from my app. And like Tom Roggero said I had to replace
UIApplication.shared.open(NSURL(string:"https://
by
self.extensionContext?.open(NSURL(string:"https://
回答5:
The classes in containing app somehow went in to the compile resources list in the extension Build Phases. I deleted them, it is ok now.
I did not do that. Obviously upgrade to Xcode 7 GM process somehow did it.
回答6:
Hi I solved this problem.
Set to Allow API Extension to No to particular framework who gives this e error like IQKeyboardManager
Consider you facing this issue for IQKeyboardManager and you installed this framework using Pod. Then your project click on Pod -> CLick on IqkeyboardManager.
And set Allow API Extension to No
来源:https://stackoverflow.com/questions/32609776/uiapplication-sharedapplication-is-unavailable