进入后台后恢复应用程序
我有一个针对 Iphone 3G、3GS 和 iPhone 的 iPhone 应用程序。 4G。 我遇到的问题是该行为与 Iphone 3G 和 iPhone 不同。 4(我没有机会在 3GS iPhone 上测试我的应用程序)。
区别在于:
在 iPhone 4 上:
- 我运行我的应用程序,并且可以正常播放。
- 我单击 iPhone 主页按钮,因此当我重新启动应用程序时,应用程序会转到后台
- ,它会从上次执行上下文继续。
在 iPhone 3G 上:
- 我运行我的应用程序,并且可以正常播放。
- 我点击 iPhone 主页按钮,应用程序进入后台?!
- 当我重新启动我的应用程序时,它会从第一次启动时重新启动。
这是一种在所有 Iphone 设备上具有相同行为的方法吗?
还是我必须自己处理这个问题?
I have an iphone app targeted for Iphone 3G, 3GS & 4G.
the issue that I have is that the behaviour is different from Iphone 3G & 4 (I didn't have the chance to test my app on 3GS iphone).
the difference is:
on iPhone 4:
- I run my app, and I play normaly.
- I click iphone home button, so the app goes to background
- when I relunch my app, it continues from last execution context.
on iPhone 3G:
- I run my app, and I play normaly.
- I click iphone home button, so the app goes to background?!
- when I relunch my app, it restart from the as it was launched for the first time.
Is these a way to have the same behaviour on all Iphone devices?
Or do I have to handle this by my self?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
iOS4增加了应用程序的后台运行,但iPhone 3G上没有。对于这些情况,您需要手动存储和恢复状态。
您可以使用一些类来帮助您完成此任务 - 例如 Github 上的 DTResurrectionKit。
iOS4 added background running to applications, bun not on the iPhone 3G. For those cases you'll need to store and restore the state manually.
There are classes that you can use to help you with this - such as DTResurrectionKit which is on Github.
给你一个更冗长的解释:
在 iOS 4.0 中,Apple 引入了后台应用程序。使用后台,失去前台的应用程序会被暂停,但可以重新激活到原来的位置,而无需开发人员为此执行任何操作。基本上,应用程序虚拟机被保存并重新创建相同的上下文。然而,后台应用程序在后台运行时可能随时被杀死。
然而,苹果公司将几款较旧的设备排除在外,尽管它们已经升级到了 4.0。 iPhone 3G 和 iPod Touch 2. Generation 没有启用后台应用程序。
因此,如果您希望在所有设备上都有相同或至少相似的行为,您将不得不推出自己的设备。在 Appdelegate 的
ApplicationWillTerminate:
函数中,您必须存储当前位置/所需的其他信息并从那里重新创建。To give you a bit more lengthy explanation:
In iOS 4.0, Apple introduced Background Apps. With Background, Apps that lose foreground get suspended but can be reactivated to the same point where they were without the Developer having to do anything for that. Basically, the Applications VM is saved and the same context recreated. However, background apps might get killed at any time when they ran in the background.
However, Apple left several older devices out of this picture, even though they got 4.0. The iPhone 3G and the iPod Touch 2. Generation did no get Background Apps enabled.
So if you want the same or at least similar behavior on all devices, you're going to have to roll your own. In the
ApplicationWillTerminate:
Function in your Appdelegate, you'll have to store the current position/other information you need and recreate from there.我认为您在 iPhone 3G 上运气不好,因为只有从运行 iOS 4.x 及更高版本的 iPhone 3GS 开始的设备才支持后台应用程序。当然,没有什么可以阻止您在应用程序终止时保存应用程序上下文并在重新启动时恢复。
如需确认 3G 支持的 iOS 4 功能,请访问:
http://support.apple.com/ kb/HT4204
I think you are out of luck on the iPhone 3G as background apps are only supported on devices starting from the iPhone 3GS running iOS 4.x and up. Of course there is nothing to stop you saving the application context when the application terminates and resuming on restart.
Confirmation of the iOS 4 features supported on the 3G can be found here:
http://support.apple.com/kb/HT4204