iPhone 关闭时仅调用 applicationWillResignActive?

发布于 2024-10-01 08:43:18 字数 770 浏览 4 评论 0原文

您好,专家们,

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

结果是:当我按下设备的开/关按钮一段时间时,applicationWillResignActive被调用。 iPhone 在屏幕上显示关闭设备的选项。如果我确认关闭,iPhone 就会关闭。但显然没有进一步调用像applicationDidEnterBackgroundapplicationWillTerminate这样的回调方法。因此,如果我不将数据保存在 applicationWillResignActive 中,所有数据都会丢失。虽然 iOS应用程序编程指南说,应该将应用程序的数据保存在applicationDidEnterBackgroundapplicationWillTerminate中。

您认为这两种方法之一是否仍然被调用并且只是不再打印在控制台中?

此致

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

白云悠悠 2024-10-08 08:43:18

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

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

如果在应用程序运行时电池已空applicationDidEnterBackgroundapplicationWillTerminate 被调用(不调用 applicationWillResignActive!)。

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!).

作业与我同在 2024-10-08 08:43:18

我认为你的测试可能是正确的。该应用程序不再处于活动状态,但它还没有进入后台——就像我打电话进来时一样——所以我认为通知是有意义的。

对此你应该做什么?我的建议是没什么。在我看来,这种事件很少发生,不值得担心。如果您想使用腰带和大括号,那么只要没有太多可存储的内容,就可以在“applicationWillResignActive”中保存状态。

I think that your test is probably correct. The app is no longer active yet it has not gone into the background -- kind of like when I call comes in -- so I think the notifications make sense.

What should you do about it? My suggestion would be nothing. It seems to me that this event happens so infrequently that it's not worth worrying about. If you want to go belt and braces then saving state in ‘applicationWillResignActive‘ should work as long as there's not much to store.

依 靠 2024-10-08 08:43:18

我测试了这个。这是调用方法的顺序。

  1. applicationWillResignActive - 当用户长时间按住设备上的锁定按钮时(并且会出现一个滑块,询问用户“滑动以关闭电源”)

如果滑动,设备将按以下顺序调用应用程序中的以下两个方法

  1. applicationDidEnterBackground< /p>

  2. applciationWillTerminate

我假设当电池耗尽时

发生同样的情况这是在运行 iOS 5.0 的 3G 上进行测试的

希望这会有所帮助。

I tested this. This is the order in which the methods are called.

  1. applicationWillResignActive - When User long holds the lock button on the device (and a slider is presented asking the user "Slide to power off"

If you slide, the device will call following two methods in your app in the order below

  1. applicationDidEnterBackground

  2. applciationWillTerminate

The the device will turn off.

I am assuming same happens when the battery drains out.

This was tested on 3Gs running iOS 5.0

Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文