开发者

applicationDidEnterBackground: and time to write on a database

开发者 https://www.devze.com 2023-02-06 09:06 出处:网络
When the application terminates, I write data on a database. As from iOS 4 applicationWillTerminate: isn\'t called, I\'ve put the same saving code both in applicationDidEnterBackground:开发者_开发百科

When the application terminates, I write data on a database.

As from iOS 4 applicationWillTerminate: isn't called, I've put the same saving code both in applicationDidEnterBackground:开发者_开发百科 and applicationWillTerminate:

I read that the task performed in applicationDidEnterBackground: has to take a few time.

So, if the writing on the db takes more, how could I manage this?


You get 5 seconds to perform any saving etc in the applicationDidEnterBackground: method.

If you need more than 5 seconds there is this UIApplication method to request a background thread which will allow for more time to do whatever you need:

- (UIBackgroundTaskIdentifier)beginBackgroundTaskWithExpirationHandler:(void(^)(void))handler

Here is Apple's example code for this:

http://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html#//apple_ref/doc/uid/TP40007072-CH5-SW12

0

精彩评论

暂无评论...
验证码 换一张
取 消