2017-10-12 149 views
0

我的iOS应用程序有一些后台线程上运行的数据处理。数据处理可能需要一些时间才能完成,所以我经常检查backgroundTimeRemaining,看看我是否需要在应用程序被杀之前清理并停止数据处理。在后台线程上查找backgroundTimeRemaining在后台线程上

为此,我呼吁:

[[UIApplication sharedApplication] backgroundTimeRemaining] 

有了最新的XCode现在这会导致运行时错误:

Main Thread Checker: UI API called on a background thread: -[UIApplication backgroundTimeRemaining] 

有没有什么办法让backgroundTimeRemaining无需添加调用返回到主每次线程?这似乎比它应该更痛苦......?

THX 迈克

+0

这似乎是一个已知的错误:http://www.openradar.me/33541766 – user1195883

回答

0

UIApplication的是UIKit中的一部分。从UIKit文档它指出:

Important Use UIKit classes only from your app’s main thread or main dispatch queue, unless otherwise indicated. This restriction particularly applies to classes derived from UIResponder or that involve manipulating your app’s user interface in any way.

所以这个调用必须在主线程上。