使用 NSOperationQueue 执行 iOS 应用程序初始化
是否可以使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
异步执行您的 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.