I have an iOS program the revolves around a global UIManagedDocument (Core Data) and I was wondering how I can ensure that it gets saved and closed properly before the program exits.
First, if I want to make sure this document gets saved right before exit, should I/can I call - (void)closeWithCompletionHandler:(void (^)(BOOL success))completionHandler in the AppDelegate method - (void)applicationWillTerminate:(UIApplication *)application. The only reason that I’m worried about doing this is that closeWithCompletitionHandler is asynchronous thus is there a chance that the program will exit before the document is fully closed?
Second, do I also have to explicitly save the document right before exit or will closing it also save it?
Thanks
UIManagedDocument will make sure the document is saved on exit, without you doing anything at all. It handles all events that cause the application to go into the background or exit (except, of course, a crash), so you don’t have to worry about that part.