简体   繁体   English

终止iPhone应用程序时调用什么方法?

[英]What method is called when iPhone app is terminated?

I am making a client server application for the iPhone and would like to know which method is called when the iPhone application is terminated. 我正在为iPhone创建客户端服务器应用程序,并且想知道在终止iPhone应用程序时调用哪种方法。 Any help would be appreciated. 任何帮助,将不胜感激。

The method relating to application lifecycle are UIApplicationDelegate methods. 与应用程序生命周期有关的方法是UIApplicationDelegate方法。 The two you want are: 您想要的两个是:

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

If on a multitasking device, applicationDidEnterBackground: will be called instead of applicationWillTerminate: . 如果多任务设备上, applicationDidEnterBackground:将被调用,而不是applicationWillTerminate: In most cases, you can perform the same code in both callbacks. 在大多数情况下,您可以在两个回调中执行相同的代码。

- (void)applicationWillTerminate:(UIApplication *)application

在您的appdelegate中

The method applicationWillTerminate gets called when your application is being shut down. 当您的应用程序关闭时,将调用applicationWillTerminate方法。 But the applicationDidEnterBackground/applicationWillResignActive methods are (now) infinitely more useful. 但是applicationDidEnterBackground / applicationWillResignActive方法(现在)无限有用。

-(void)applicationWillTerminate:(UIApplication *)application in your application delegate will be called. -(void)applicationWillTerminate:(UIApplication *)application程序委托中的应用程序将被调用。 Check this blog post with chart that describes in detail what messages will be sent during launch, termination and when transitioning between background and foreground. 请查看此博客文章,并附上图表 ,其中详细描述了在启动,终止以及在背景和前景之间转换时将发送哪些消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM