to save some variables of my apps I use:
-(void)applicationWillTerminate:(UIApplication *)application {
NSUserDefaults *prefs = [NSUserDefaults standardU
If you mean hitting the lock button on the top of the phone by saying "switching on/off", then it won't work, because locking the phone does not cause an application to quit.
Your applicationWillTerminate:
method is only called when you exit you're application to the home screen or to some other application. When the user presses the Sleep button, applicationWillResignActive:
will be send to your application-delegate.
Apple's iPhone OS Programming Guide has a section on handling interruptions.