iPhone. Shouldn't hitting the home button cause UIApplicationDelegate's dealloc to be called

☆樱花仙子☆ 提交于 2019-12-13 02:15:33

问题


I have put NSLogs in all my classes including my UIApplicationDelegate subclass. I am curious - and a bit nervous - about why I am not seeing them echo anything when I press the home button. I am running in the XCode simulator.

Since iPhone/iPad runs a single app at a time, doesn't hitting the home button discard all traces of the running app?

Thanks,
Doug


回答1:


When an app is terminated, its memory is simply freed. Dealloc is not called, it does not pass go or collect $200. This is normal and intended.




回答2:


Chuck is correct, the dealloc's don't matter at that point. If you want to do something as your app is expiring, implement this in your app delegate class:

- (void)applicationWillTerminate:(UIApplication *)application {
   // goodbye...
}



回答3:


You should implement -(void)applicationWillTerminate:(UIApplication*)application{ } this method will get called when user hit home button.




回答4:


You might also want to think about the additional multitasking support that has been announced. Obviously the details are still under NDA, but pushing Home does not necessarily stop your app.

And think about the various circumstances where your app may already be terminated quickly (e.g. if a call comes in and the system runs out of RAM). Do your cleanup with the application lifecycle messages.



来源:https://stackoverflow.com/questions/2679847/iphone-shouldnt-hitting-the-home-button-cause-uiapplicationdelegates-dealloc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!