To restart the app from the home screen and not fr

2020-07-22 19:38发布

问题:

When we play our app on the device(ios 4.0 and above) and leave mid workflow, and return later, we return mid workflow. I want that it should not replay from the same left point rather the main screen should load(i.e, the same thing that happens on calling viewDidLoad of our rootViewController).

Please give suggestions if it is possible and if not then please post the reason behind that.

回答1:

Here's an alternative approach, disable background mode and restart your app every time it enters the foreground: add UIApplicationExitsOnSuspend key to your app's info.plist and set its value to YES.

UIApplicationExitsOnSuspend

UIApplicationExitsOnSuspend (Boolean - iOS) specifies that the application should be terminated rather than moved to the background when it is quit. Applications linked against iOS SDK 4.0 or later can include this key and set its value to YES to prevent being automatically opted-in to background execution and application suspension. When the value of this key is YES, the application is terminated and purged from memory instead of moved to the background. If this key is not present, or is set to NO, the application moves to the background as usual.

This key is supported in iOS 4.0 and later.



回答2:

So actually you want to quit the app on Home button press and restart?i.e turn multitasking off?
Search for info on UIApplicationExitsOnSuspend



回答3:

Yes you call your rootviewcontroller from applicationDidUnhide to do so. You'll have to twist your logic a little (have to reset your variables on this method call).

Edit: You should instead use applicationDidBecomeActive. Reference is on same link.