当应用程序终止时,我将数据写入数据库。
从 iOS 4 开始,applicationWillTerminate: 没有被调用,我在 applicationDidEnterBackground: 和 applicationWillTerminate: 中放置了相同的保存代码
我读到在 applicationDidEnterBackground: 中执行的任务必须花费一些时间。
那么,如果在数据库上写入需要更多的时间,我该如何管理呢?
最佳答案
您有 5 秒的时间在 applicationDidEnterBackground: 方法中执行任何保存等操作。
如果您需要超过 5 秒,可以使用此 UIApplication 方法来请求后台线程,这将允许您有更多时间做任何您需要的事情:
- (UIBackgroundTaskIdentifier)beginBackgroundTaskWithExpirationHandler:(void(^)(void))handler
这是 Apple 的示例代码:
关于ios - applicationDidEnterBackground : and time to write on a database,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4769967/