I’ve recently implemented a system of saving a number of arrays, boolean values and ints into the user defaults. Now i currently use three buttons on my interface to test the functionality out and it works correctly, however i am running into problems trying to automate the save system.
Essentially i want the app to save the data either when it terminates or when it is pushed to the background. It then only loads the data when the app is restarted fully.
I’ve tried using the folowing appdelegate delegate methods to run the methods i created to save and load:
didFinishLaunchingWithOptions:
applicationWillTerminate:
But they don’t seem to work, i know that i’ll need the enter foreground method for saving when the app is pushed back, but presently nothing works. The app appears to crash or fails to save and load the data.
Any help would be appreciated.
I think you should save your
defaultsin- (void)applicationDidEnterBackground:(UIApplication *)applicationmethod.And, for again accessing
defaults, fetch data in- (void)applicationWillEnterForeground:(UIApplication *)application
or in
- (void)applicationDidBecomeActive:(UIApplication *)application
method.