UIApplication.sharedApplication is unavailable

I am trying to get the delegate link of my application from the UIViewController, but I keep getting this error message:

'sharedApplication ()' is not available: use controller-based solutions instead.

I read all the articles devoted to this kind of messages, but my problem seems to be unrelated, since I do not use a third-party structure. Although the Today extension is part of my application, the class in which the error occurs is completely 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 in the playground, it works great. What am I missing?

+20
ios swift2
source share
3 answers

The problem is resolved. I was back in the settings of my application and came across

Require Only AppExtension-Safe API 

set to YES. The default value is NO. When I set this to NO, the error disappeared.

I’m sure I don’t remember ever touching or even knowing about it, but, fortunately, it works now.

+59
source share

In case someone discovered this error 3 years after the question. Ensure that the target membership in the swift file does not contain the Today extension.

+1
source share

I encountered the same error when I created and added a new target to my project (the goal of a remote maintenance notification) and incorrectly added the target definition to my subfile.

I followed the instructions of a third-party notification platform, and they did not know where to place the definition of the goal. Initially, I added a goal definition to my main goal, much like a Tests goal definition. This error led me to this error.

I moved the definition of the remote service notification target beyond my primary goal to the end of my subfile, and this solved my problem.

0
source share

All Articles