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

标签 ios background-process uiapplicationdelegate springboard

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

我可以将它放入 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/

相关文章:

iframe 中的 IOS 6.0.1 Safari Scroll pdf

java - 使用 java.exe 的静默模式执行

android - 防止 Activity 在后台做某事

ios5 - 在 ipad 应用程序启动时显示模态视图

iphone - iOS 会在后台杀死应用程序吗?

ios - 下载时如何处理iOS应用程序 sleep 后崩溃?

ios - 使用 swift 添加多个文本字段到 firebase

php - 表情符号到 JSON 编码,发布到网络服务器

iOS:推送通知、UIApplicationStateInactive 和快速应用切换

ruby-on-rails - 如何使用 Sidekiq 将文件上传推送到后台?