I have an iphone app targeted for Iphone 3G, 3GS &am开发者_如何学Gop; 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?
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.
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.
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
精彩评论