应用程序从后台唤醒时重新启动 [英] App restarts when woken from background

查看:145
本文介绍了应用程序从后台唤醒时重新启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

G'day iOS Guru's,

G'day iOS Guru's,

我已经广泛搜索了一个答案,但找不到答案(我打赌我的问题的第一个回答是另一个类似的问题,但我找不到它。)

I have searched extensively for an answer, but can't find one (I bet the first response to my question will be to another similar question, but I cant find it).

无论如何,我的问题是我正在运行一个简单的地图应用程序,用户可以使用在掉落的针脚周围自定义圆圈覆盖。

Anyway, my problem is that I am running a simple map app that the user can drop pins on the map with a customised circle overlay around the dropped pin.

当应用程序进入后台(iphone锁定或按下主页按钮)时,如果我在约5分钟内重新进入应用程序,针脚仍在那里,应用程序重新打开到最后一个屏幕。

When the app goes into the background (iphone locked or home button pressed), if I re-enter the app within ~ 5 mins, the pins are still there and the app reopens to the last screen.

一切都很好。

但是,如果我将应用程序留在后台超过5分钟,应用程序将重新启动并且所有引脚都将丢失。

However, if I leave the app in the background for longer than 5 mins, the app restarts and all the pins are lost.

我在plist中有应用程序不在后台运行= NO,并且在所需的后台模式下启用了应用寄存器以进行位置更新。

I have "Application does not run in background = NO" in the plist, and also enabled "App registers for location updates" under Required background modes.

如何阻止应用在进入后台并加载上次打开的视图后重新启动?

How can I prevent the app from restarting after it enters the background and load the last opened view?

推荐答案

如果需要额外的资源来执行前台正在进行的操作,iOS可以并且将会在后台终止您的应用。

iOS can, and will, terminate your app while it's in the background if it needs additional resources to carry out whatever's going on in the foreground.

您需要确保在应用程序终止时保存/存档您的数据,并在重新启动时解压缩以便返回到用户最后的位置。执行此操作的传统方法是使用 applicationDidEnterBackground 方法,该方法在您的应用程序暂停时调用。然后,您可以保存所需的所有数据,以便在以后终止您的应用时彻底恢复。

You need to ensure that your data is saved/archived when your app is terminated, and unpacked when re-launched so as to go back to where the user last was. The traditional way to do this is to use the applicationDidEnterBackground method, which is called when your app is suspended. You can then save all the data you need in order to resume cleanly in case your app is later terminated.

但是,如果您的目标是iOS 6及更高版本,则可以利用新功能 - State Presumption&恢复(链接到文档)。状态恢复将一些(但不是全部)繁重的工作卸载到iOS上,它可以自动对UI进行快照,并提供更简单的方法来保存和恢复数据。

However, if you're targeting iOS 6 and upwards you can take advantage of a new feature - State Presumption & Restoration (link to documentation). State restoration off-loads some (but not all) of the heavy lifting onto iOS, and it can automatically snapshot your UI and provides easier ways to preserve and restore data.

这篇关于应用程序从后台唤醒时重新启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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