ApplicationDidEnterBackground: and time for writing to the database

when the application terminates, I write data to the database.

As from iOS 4 applicationWillTerminate: is not called, I put the same save code as in applicationDidEnterBackground: and applicationWillTerminate:

I read that the task running in applicationDidEnterBackground: should go through several times.

So, if writing to db takes longer, how can I do this?

+4
source share
1 answer

You get 5 seconds to make any savings, etc. in the applicationDidEnterBackground: method.

If you need more than 5 seconds, this UIApplication method will request a background thread, which will allow more time to do everything you need:

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

Here is an example of Apple code for this:

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

+4
source

Source: https://habr.com/ru/post/1336617/


All Articles