gpt4 book ai didi

ios - 调用 applicationDidEnterBackground 后我有多少时间?

转载 作者:行者123 更新时间:2023-11-28 18:11:58 24 4
gpt4 key购买 nike

我想发送一个时间戳到远程服务器,并等待成功的回调,然后将时间戳存储在本地,如果远程服务器没有响应。

我可以将它放入 applicationDidEnterBackground 实现中吗?

最佳答案

根据 iOS 开发者库 UIApplicationDelegate Protocol Reference

Your implementation of this method has approximately five seconds to perform any tasks and return. If you need additional time to perform any final tasks, you can request additional execution time from the system by calling beginBackgroundTaskWithExpirationHandler:. In practice, you should return from applicationDidEnterBackground: as quickly as possible. If the method does not return before time runs out your app is terminated and purged from memory.

You should perform any tasks relating to adjusting your user interface before this method exits but other tasks (such as saving state) should be moved to a concurrent dispatch queue or secondary thread as needed. Because it's likely any background tasks you start in applicationDidEnterBackground: will not run until after that method exits, you should request additional background execution time before starting those tasks. In other words, first call beginBackgroundTaskWithExpirationHandler: and then run the task on a dispatch queue or secondary thread.

因此您有大约 5 秒 来执行任何任务并在“applicationDidEnterBackground”方法中返回。

关于ios - 调用 applicationDidEnterBackground 后我有多少时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16267486/

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