2

How do I make my iPhone app start at the same place each time, i.e. my 'home' screen? I do NOT want the user to return to where they were last time they played - right in the middle of gameplay - but that's what's happening. Thanks in advance for any tips!

4 Answers 4

6

You need to set the UIApplicationExitsOnSuspend key in your info.plist file to YES. Then the app will quit when the home button is pressed, and launch fresh when it is opened again.

3
  • Hey thank! - but I don't even see that member in my info.plist - is it an iPhone4-only field? Apr 6, 2011 at 11:51
  • It only does anything on iPhone 4, but you can safely add it to the info.plist file for earlier operating systems; it will be ignored on 3.x and 2.x.
    – peterjb
    Apr 6, 2011 at 12:50
  • Just create a new entry in the plist, paste the key in the key column, make the type column BOOL, and check the box--it'll work. It just won't necessarily get a plain english translation for it's name in Xcode.
    – peterjb
    Apr 6, 2011 at 12:57
3

This is presumably only happening because your app isn't really being stopped - it's simply being backgrounded. (If you double click the home button whilst viewing springboard does it show up at the bottom? If so, it's still running.)

You can disable this behaviour (so your app quits when the user hits the home button) by setting the UIApplicationExitsOnSuspend key (known as "Application does not run in background" within Xcode) in your info.plist file. See Apple's Information Property List Key Reference docs for more information.

Alternatively, you could simply capture the applicationDidEnterBackground: UIApplicationDelegate method in your app's add delegate and handle the situation from there programatically. (i.e.: Do whatever you need to do to reset your app back to the 'home' screen, etc.)

1
  • aha yes, it's in the background - but I don't have the UIApplicationExitsOnSuspend field showing in my info.plist file - as if it thinks it's a 3.2 file? Apr 6, 2011 at 11:59
2
- (void)applicationWillResignActive:(UIApplication *)application {

[self.navigationController popToRootViewControllerAnimated:YES];   

}

/* Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. */

2
  • How do you even know if he's using a UINavigationController? Apr 6, 2011 at 11:47
  • /* Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. */ Apr 6, 2011 at 11:47
1

Set UIApplicationExitsOnSuspend to YES int the Info.plist.

1
  • Thanks for all these responses! - OK I see now it's an iPhone4 field; but don't I want to target 3.2 so it runs on old phones? Apr 6, 2011 at 11:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.