问题
I'm working on an app that needs to run through a protocol from beginning to end. How do I force the app to always start at the beginning when brought back from the background, regardless of where it was left. Thanks
回答1:
If your goal is to restart the app from scratch at every start up, simply add/change the key UIApplicationExitsOnSuspend
to YES
in your info.plist file
Here's the relevant link in the documentation http://developer.apple.com/library/ios/#documentation/general/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html
回答2:
One option is to use exit()
. However, that method is only useful for testing/programming purposes. Apple will not accept that being in your code.
Another option would be to create a global session similar to the method used by most social media API's, and in your App Delegate's:
- (void)applicationDidEnterBackground:(UIApplication *)application
set the global session to closed. Then just set your protocol logic to restart if the session is closed.
I hope that helps!
回答3:
write your application starting code in applicationDidBecomeActive
method, because this method calls both time when you start your application first time & also when you cames from background
来源:https://stackoverflow.com/questions/14533997/how-do-i-force-an-app-to-always-start-from-scratch-when-it-returns-from-the-back