使用 NSOperationQueue 执行 iOS 应用程序初始化

发布于 2024-12-29 14:38:11 字数 405 浏览 3 评论 0原文

是否可以使用 NSOperationQueue addOperationWithBlock 来延迟初始化代码,以便应用程序不会被 iOS 看门狗杀死?

我们知道,如果应用程序在 application: didFinishLaunchingWithOptions 或 applicationDidBecomeActive 中花费太多时间,iOS 就会杀死该应用程序。

但我还有很多初始化工作要做。目前,我正在执行一堆同步 HTTP 请求(让它同步:)),这可能需要不可预测的持续时间。

你能建议一个更好的解决方案来解决这个问题吗?

谢谢你!

编辑:大家,同步的 HTTP 请求不是问题的主题。 我集成了很多第三方SDK。我必须初始化所有这些,但我不知道它们在初始化期间在做什么。我只是想把被iOS杀掉的风险降到最低。

Is it OK to use NSOperationQueue addOperationWithBlock to delay initialization code, so the app was not killed by an iOS watchdog?

As we know iOS kills the app if it spends too much time in application: didFinishLaunchingWithOptions or in applicationDidBecomeActive.

But I have a lot of things to do for initialization. Currently I am doing a bunch of synchronious HTTP requests (let it be synchronious :) ) whcih can take unpredicatble duration of time.

Could you suggest a nicer solution to this problem?

Thank you!

EDIT: Everyone, synced HTTP requests are not a subject of the question.
I have a lot of third-party SDKs integrated. I have to initialize all of them but I have no idea what they are doing during initialization. I am just trying to minimize the risk of being killed by iOS.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柒夜笙歌凉 2025-01-05 14:38:11

异步执行您的 Web 请求,并在必要时在请求进行时显示加载 UI。您不应该永远application:didFinishLaunchingWithOptions: 中运行同步 Web 请求,看门狗的存在是有原因的。

Perform your web requests asynchronously and if necessary show a loading UI while they progress. You should never run synchronous web requests in application:didFinishLaunchingWithOptions:, watchdog is there for a reason.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文