2017-10-12 140 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.

所以這個調用必須在主線程上。