iPhone simulator and applicationWillTerminate()

妖精的绣舞 提交于 2019-11-29 07:46:14

问题


When my app is run in the iPhone simulator, the delegate method

- (void)applicationWillTerminate:(UIApplication *)application

is only called the first time I hit the iPhone simulator's home button.

After the home button is pressed and the app is launched again, hitting the home button does not call the delegate method.

What is going on here? Am I misunderstanding something fundamental?


回答1:


I suspect that it is being called, but that you are getting confused because after you hit the Home button in the Simulator, you've ended the current session in Xcode. You probably have an NSLog in your applicationWillTerminate: method, yes? Once you hit the Home button, NSLogs no longer show up in Xcode's run console. If you open /Applications/Console.app I expect they'll show up there.




回答2:


- (void)applicationWillTerminate:(UIApplication *)application

is called when the application "terminates". If you are using iOS then the app will NOT terminate when the home button is pressed, unless you have disabled multi-tasking for your app or the user does not have a "multi-tasking supported" device.

- (void)applicationDidEnterBackground {

is now used when the user presses the home button. Unless (as I previously said) you have disabled multi-tasking for your app or the user does not have a "multi-tasking supported" device.



来源:https://stackoverflow.com/questions/368021/iphone-simulator-and-applicationwillterminate

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