IOS 4.0多任务支持场景不需要保存状态吗?

发布于 2024-10-23 01:04:48 字数 424 浏览 3 评论 0原文

我对何时需要为 iPhone 应用程序保存状态感到有点困惑。特别是对于一个人的Iphone IOS版本支持多任务处理的场景,当你回来时,它看起来确实处于相同的状态(无论如何对于我的简单应用程序来说)。

问题 - 您能否澄清“需要保存 iPhone 应用程序的状态”和多任务支持如何一起发挥作用。

希望响应可以帮助澄清以下方面:

  1. 对于多任务支持场景(当用户没有显式终止应用程序时),是否需要保存状态?或者 IOS 是否会为您执行此操作(对于我的简单应用程序来说似乎是这样做的)。

  2. 如果1的答案是YES,那么什么时候你真正需要保存状态?

  3. 如果 1 的答案是否定的,那么当 IOS 确实让您的应用程序在后台“运行”时,与不丢失相比,您到底会丢失哪些数据/状态?

谢谢

I getting a little confused about when one needs to save state for an iPhone app. In particular for the scenario where one's Iphone IOS version supports multitasking, and when you come back to it, it does appear to be in the same state (for my simple app anyway).

Question - Can you clarify how the "need to save state for an iPhone app", and the multitasking support play together.

Hopefully the response can help clarify aspects such as:

  1. For the multitasking support scenario (when a user doesn't explicitly terminate the application), is there any need at all to save state? Or does IOS do it for you (which it kind of appears it does for my simple app).

  2. If the answer to 1 is YES, then at what point do you really need to save state then?

  3. If the answer to 1 is NO, then exactly what data/state do you lose versus not-lose when IOS does keep your application "running" in the background?

thanks

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

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

发布评论

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

评论(3

阿楠 2024-10-30 01:04:48

1A。是的。因为...

1B。你不知道。操作系统通常会在较新的设备上保存状态,但这并不能保证,也不会总是发生。在较旧的设备上,操作系统不会保存状态。

2A。即使答案为1B。是的,操作系统仍然可以删除应用程序的状态以节省内存。因此,您仍然需要保存您不希望在应用程序暂停后丢失的任何状态。

3A。如果您的应用程序不检查恢复时的时钟,则可能会丢失时间记录(来自 NSTimer 滴答声等)。

1A. Yes. Because...

1B. You don't know. The OS usually saves state on newer devices, but this is not guaranteed, and will not always happen. On older devices the OS won't save state.

2A. Even if the answer to 1B. is YES, the OS could still delete your app's state to save memory. So you still need to save any state you don't want potentially lost after your app is suspended.

3A. Your app may lose track of time (from NSTimer ticks, etc.) if it doesn't check the clock on resume.

客…行舟 2024-10-30 01:04:48

要支持多任务,您所要做的就是针对 4.0 或更高版本进行编译。

您应该将应用程序数据保存到文件中,但 IOS 会将所有视图和视图控制器保留在内存中,并在应用程序切换回来时从中断处恢复。

请记住,当您的应用程序在后台运行时,IOS 可以随时完全终止它以尝试回收内存,因此请确保您的用户数据得到保留。

All you have to do to support multitasking is compile against 4.0 or greater.

You should save application data to a file, but IOS will keep all your views and viewcontrollers in memory and will resume where it left off when the app is switched back.

Keep in mind, that when your app is in the background, IOS can fully terminate it at anytime in an attempt to re-claim memory so make sure your user data is persisted.

鸵鸟症 2024-10-30 01:04:48

通常,在多任务处理下,应用程序会继续运行,并且无需显式保存应用程序的状态。但是,如果手机内存不足,它很可能决定在后台模式下转储您的应用程序。

对于没有后台模式的手机(例如 3G),您始终需要保存状态。

最重要的是,每当进入后台时,您都需要保存状态,以防应用程序稍后从内存中删除。您只需在重新启动时重新读取它,而不是从后台返回时读取它。

至于需要保存“什么状态”,这实际上取决于您的特定应用程序。也许是选定的选项卡或导航?很大程度上取决于用户对不丢失任何工作的期望。

Normally with multitasking the application continues to run and there would be no need to explicitly save the application's state. However, if the phone is running low on memory, it may very well decide to dump your application while it's in background mode.

For phone's that do not have background mode (e.g. the 3G) you would always need to save state.

Bottom line, you'll want to save state whenever going into background in the event the application is removed from memory later. You would only have to read it back on a re-launch, not upon coming back from background.

As far as "what state" needs to be saved, it really depends on your particular application. Perhaps the selected tab or navigation? A lot depends on user expectation of not losing any work.

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