iPhone关闭时只调用applicationWillResignActive? [英] Only applicationWillResignActive called when iPhone shuts down?

查看:399
本文介绍了iPhone关闭时只调用applicationWillResignActive?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好专家,



我已经测试了当应用程序处于活动状态时,当iPhone 关闭时,我的应用程序正在受到什么影响。为此,我在xcode调试器控制台中记录了应用程序生命周期的回调方法。



结果是:当我按下设备的开/关按钮时时间 applicationWillResignActive 被调用。 iPhone显示关闭屏幕上设备的选项。如果我知道关闭,iPhone将关闭。但显然没有其他回调方法,如 applicationDidEnterBackground applicationWillTerminate 被称为。因此,如果我不将其保存在 applicationWillResignActive 中,则所有数据都将丢失。虽然 iOS应用程序编程指南说,应该在 applicationDidEnterBackground applicationWillTerminate 中保存应用程序的数据。



你怎么看,这两种方法中的一种仍然被调用,只是不再打印在控制台中了?



祝你好运

解决方案

我做了一些进一步的测试:



我已经将被调用的生命周期方法保存在数据库中,并在应用程序运行时关闭了iPhone。 实际上只调用 applicationWillResignActive
但是在关闭后我的应用程序处于未运行状态,因为启动它会启动调用应用程序:didFinsihLaunchingWithOptions: applicationDidBecomeActive 。因此,如果我不将其保存在 applicationWillResignActive 中,应用程序数据就会丢失。



如果电池当应用程序运行时 applicationDidEnterBackground applicationWillTerminate 被调用没有调用 applicationWillResignActive !)。


Hallo experts,

I've tested what's happing with my app when the iPhone is switched off while the app is active. For this purpose I logged the callback methods of the app's lifecycle in the xcode debugger console.

The result was: When I press the on/off button of the device for some time applicationWillResignActive is called. The iPhone shows an option to switch off the device on the screen. If I ackknowlege to switch off, the iPhone shuts down. But apperently no further callback methods like applicationDidEnterBackground or applicationWillTerminate are called. As result all data would be lost if I don't save it in applicationWillResignActive. Although the iOS Application Programming Guide says, one should save an app's data in applicationDidEnterBackground and applicationWillTerminate.

What do you think, is one of the two methods still called and is only not printed in the console anymore?

Best regards

解决方案

I've made some further tests:

I've saved the called lifecycle methods in a database and turned off the iPhone while may application was running. Actually only applicationWillResignActive is called. But after the shut down my application resides in the state "not running", because launching it initiates calls of application:didFinsihLaunchingWithOptions: and applicationDidBecomeActive. So the application data is lost if I don't save it in applicationWillResignActive.

If the battery is empty while an application is running applicationDidEnterBackground and applicationWillTerminate are called (no call of applicationWillResignActive!).

这篇关于iPhone关闭时只调用applicationWillResignActive?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆