In applicationWillTerminate applicationWillTerminate delegates and their associated methods, you need to check if any background threads were unsaved changes and save them before allowing the application to stop working or go to background.
source share