Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIApplication.sharedApplication() is unavailable

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.

like image 891
Ahmet Akkök Avatar asked Sep 16 '15 13:09

Ahmet Akkök


2 Answers

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

enter image description here

like image 77
Stephen Chen Avatar answered Oct 14 '22 20:10

Stephen Chen


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.

like image 34
Scott Austin Avatar answered Oct 14 '22 21:10

Scott Austin