- 必须仅从主线程调用[UIApplication委托] [英] -[UIApplication delegate] must be called from main thread only

查看:105
本文介绍了 - 必须仅从主线程调用[UIApplication委托]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个警告会导致一个严重的问题,因为我真的无法使用Xcode 9 beta 2在主线程之外调用委托。奇怪的是,当我使用Xcode 8.3.3时,这是有效的。

This warning leads to a serious problem cause I really can't call the delegate outside of the main thread using Xcode 9 beta 2. Strange thing is that this was working when I was using Xcode 8.3.3.

另外我认为仅从主线程调用委托只是好习惯,不是吗?那么为什么这会导致应用程序崩溃?

Also I thought it would only be good practice to call delegates from main thread only, isn't it? So why is this causing the app to crash now?

推荐答案

只需从主线程中调用它就可以了。

Just call it from the main thread like this.

dispatch_async(dispatch_get_main_queue(), ^{
  [[UIApplication delegate] fooBar];
});

像这样接触你的应用代表,暗示你的架构可以使用一点点清理。

Reaching out to your app delegate like this, is a hint that your architecture could use a little cleanup.

您可以从任何您想要的线程中调用代理。你只需要确保你在UIKit调用的主线程上。或者您正在使用CoreData对象所期望的正确线程。这完全取决于您的对象具有的API合约。

You can call delegates from any thread you want. You only need to make sure you're on the main thread for UIKit calls. Or that you're on the correct thread your CoreData objects expect. It all depends on the API contract your objects have.

这篇关于 - 必须仅从主线程调用[UIApplication委托]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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