How do I force an app to always start from scratch when it returns from the background?

断了今生、忘了曾经 提交于 2020-02-02 06:04:44

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!