views:

29

answers:

2

I am wanting to save some app state data for when the user is quitting the app. I am thinking that I should be using the applicationWillTerminate method inside of my appDelegate, but when I try and do anything there, it's not doing anything:

- (void) applicationWillTerminate:(UIApplication *)application {
NSLog(@"test");
 }

When I run my app, and do some stuff, and hit the home button to quit the app, nothing comes over the console...

Do I have to implement the applicationWillTerminate method in the appDelegate? The user of my app will most likely be in a Reader view when they leave, is there anyway to implement the app will close method there? Thanks

+1  A: 

see this link http://stackoverflow.com/questions/368021/iphone-simulator-and-applicationwillterminate for older iOS versions;

but remember the Home button does not necessarily terminate the application is ios4... you should use applicationDidEnterBackground but would suggest both places applicationWillTerminate and applicationDidEnterBackground

Adding the UIApplicationExitsOnSuspend key to your application’s Info.plist file and setting its value to YES will make you application quit when you hit the home button, even on iOS4

Aaron Saunders
Thats just the clarification I needed, thanks a bunch
Jerry
+2  A: 

In iOS 4, the applicationWillTerminate: method is only called if you opt out of the background execution model. In the standard iOS 4 application lifecycle, applications are suspended (not terminated) when the home button is pressed. Your application delegate will receive an applicationWillResignActive: message followed by an applicationDidEnterBackground: message. The applicationDidEnterBackground: method is a good place to save user data.

James Huddleston