Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
441 views
in Technique[技术] by (71.8m points)

ios - UIApplication.sharedApplication not available

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...