gpt4 book ai didi

ios - 在后台线程上查找backgroundTimeRemaining

转载 作者:行者123 更新时间:2023-12-01 16:23:29 27 4
gpt4 key购买 nike

我的iOS应用程序具有一些在后台线程上运行的数据处理。数据处理可能需要一些时间才能完成,因此我会定期检查backgroundTimeRemaining,以查看是否需要整理和停止数据处理,然后再终止该应用程序。

为此,我调用:

[[UIApplication sharedApplication] backgroundTimeRemaining]

使用最新的XCode现在会导致运行时错误:
Main Thread Checker: UI API called on a background thread: -[UIApplication backgroundTimeRemaining]

有没有什么方法可以在不每次都将调用添加回主线程的情况下获取backgroundTimeRemaining?这似乎比应该的要痛苦得多……?

谢谢
麦克风

最佳答案

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.



因此,此调用需要在主线程上。

关于ios - 在后台线程上查找backgroundTimeRemaining,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46701006/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com