How do I force an app to always start from scratch

2019-05-10 20:12发布

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

3条回答
The star\"
2楼-- · 2019-05-10 20:46

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

查看更多
孤傲高冷的网名
3楼-- · 2019-05-10 20:51

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!

查看更多
ゆ 、 Hurt°
4楼-- · 2019-05-10 20:52

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

查看更多
登录 后发表回答