UIApplication.sharedApplication() is unavailable

后端 未结 6 2056
情话喂你
情话喂你 2020-12-20 13:48

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

相关标签:
6条回答
  • 2020-12-20 14:03

    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://
    
    0 讨论(0)
  • 2020-12-20 14:05

    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

    0 讨论(0)
  • 2020-12-20 14:06

    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.

    0 讨论(0)
  • 2020-12-20 14:09

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

    0 讨论(0)
  • 2020-12-20 14:15

    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.

    0 讨论(0)
  • 2020-12-20 14:21

    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.

    0 讨论(0)
提交回复
热议问题