applicationWillTerminate works as long as I don't switch off the iPhone

前端 未结 2 350
执笔经年
执笔经年 2021-01-26 06:44

to save some variables of my apps I use:

-(void)applicationWillTerminate:(UIApplication *)application {

NSUserDefaults *prefs = [NSUserDefaults standardU         


        
相关标签:
2条回答
  • 2021-01-26 07:01

    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.

    0 讨论(0)
  • 2021-01-26 07:03

    According to Apple's documentation

    "NSUserDefaults caches the information to avoid having to open the user’s defaults database each time you need a default value."

    If you want to make sure things are saved you should call "synchronize" on your prefs.

    0 讨论(0)
提交回复
热议问题