UIApplication.sharedApplication() is unavailable

谁说我不能喝 提交于 2019-11-28 13:20:50

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.

While I was making a framework. I faced this problem. Manually set it to NO solved my problem.

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.

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://

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.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!