views:

41

answers:

2

I am building an iPhone app. Currently when I close the app and relaunch it, it relaunches on the last viewed view. Instead I want to be able to reinitialize the app, and present the view that's most appropriate for the application's state (based on what's in the database).

How can I do that?

+1  A: 

I presume it's iOS4 - your app is not being terminated in this case, it is merely being suspended.

You need to follow the instructions here: http://maniacdev.com/2010/07/screw-multi-tasking-how-to-make-your-ios-4-apps-exit-for-real/ which will terminate the app when the user presses the home button.

You need to add the appropriate 'correct view' logic to your application's start-up code once you've done this.

For the purposes of expediency, I'm adding the instructions here:

  1. Open your info.plist file
  2. Add The Key UIApplicationExitsOnSuspend or Select Application does not run in background
  3. Set the new key to YES or Fill in the tick box
Petesh
Thanks for that! Totally didn't cross my mind that it could be to do with multitasking functionality in iOS4. This worked a treat.
adriaan
+2  A: 

You have two options. You can follow Petesh's suggestion to make your app always terminate, or you can implement -applicationWillEnterForeground in your app delegate and reset things there.

Seamus Campbell
Thanks for your answer. I will go with Petesh's suggestion for now, and will keep yours for a future release (trying to keep things simple for the first release)
adriaan