gpt4 book ai didi

ios - 我可以在 `applicationWillTerminate:` 中存档对象吗?

转载 作者:行者123 更新时间:2023-11-28 08:21:44 26 4
gpt4 key购买 nike

我们知道,当app被杀死时,在AppDelegate中,系统会调用applicationWillTerminate:方法。

但是你知道,如果 archive 是一个 singleton,这是一个非常重要的事情,而且如果有一个 fetch data Action , app 是否会在 networkarchive 尚未完成时被杀死?

我可以在 applicationWillTerminate: 方法中archive singleton 吗?

applicationWillTerminate: 方法:

func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.

}

最佳答案

来自 docs :

Your implementation of this method has approximately five seconds to perform any tasks and return. If the method does not return before time expires, the system may kill the process altogether.

鉴于此信息,如果您确定可以从网络中检索一些信息并在可能不到 5 秒的时间内存档您的对象,那么您可以使用该方法进行操作。

就个人而言,我不会在那里这样做,因为您完全受制于您的互联网连接质量,这很容易导致您的网络请求花费超过 5 秒。

关于ios - 我可以在 `applicationWillTerminate:` 中存档对象吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41115535/

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