Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIApplication.sharedApplication not available

Tags:

I'm trying to get a reference to my app delegate from a UIViewController but I keep getting an this error message:

'sharedApplication()' is unavailable: Use view controller based solutions where appropriate instead.

I've been reading all the articles dealing with this kind of message but my problem seems unrelated as I'm not using any third party framework. While a Today Extension is part of my app, the class in which the error occurs is totally unrelated. I even created a completely new class and keep getting the same error:

http://i.stack.imgur.com/mp2qs.png When I do the same thing in a playground it works fine. What am I missing?

like image 859
DoertyDoerk Avatar asked Dec 11 '15 13:12

DoertyDoerk


Video Answer


3 Answers

Problem solved. I've been to the Build Settings of my app again and stumbled over

Require Only AppExtension-Safe API 

all set to YES. The default though is NO. When I set this to NO the error disappeared.

I sure don't remember ever touching or even knowing about this but luckily now it works.

like image 144
DoertyDoerk Avatar answered Oct 15 '22 18:10

DoertyDoerk


I ran into the same error when I created and added a new target to my project (a Remote Service Notification target) and added the target definition incorrectly in my podfile.

I was following directions from a third party notification platform and they were unclear as to where to place the target definition. Initially, I added the target definition within my main target, much like the Tests target definition. This mistake led me to this error.

I ended up moving the remote service notification target definition outside of my main target to the bottom of my podfile and that resolved my problem.

like image 35
drquiz Avatar answered Oct 15 '22 19:10

drquiz


In case anyone came through this error after 3 years from the question time. Make sure that the swift file target Membership doesn't include a Today Extension.

like image 21
Mohamed ElBasyouni Avatar answered Oct 15 '22 17:10

Mohamed ElBasyouni