iPhone app startup

2019-07-11 16:36发布

问题:

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!

回答1:

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.



回答2:

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.)



回答3:

- (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. */



回答4:

Set UIApplicationExitsOnSuspend to YES int the Info.plist.