UIApplication.sharedApplication不可用 [英] UIApplication.sharedApplication not available

查看:733
本文介绍了UIApplication.sharedApplication不可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从UIViewController获取对我的app委托的引用,但我不断收到此错误消息:

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


' sharedApplication()'不可用:改为使用基于视图控制器的解决方案。

'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:


当我在操场上做同样的事情时它工作正常。我错过了什么?

When I do the same thing in a playground it works fine. What am I missing?

推荐答案

问题解决了。我再次去了我的应用程序的构建设置,偶然发现了

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

Require Only AppExtension-Safe API

全部设为YES。默认值为NO。当我将此设置为NO时,错误消失。

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.

这篇关于UIApplication.sharedApplication不可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆