سؤال

I have an app which I want to recover from being killed while running in the background.

What seems to happen is that if the app is killed in the background due to memory pressure, on re-entering the app the app returns to the root view controller.

It appears from testing that neither viewWillAppear or viewDidLoad are called on the root view controller in this case, therefore I cannot execute any code this way on resume.

My question is which methods are called in the above scenario and, ultimately, how can I send a message to the root view controller to handle the case where the app is restarting after having been killed in the background ?

هل كانت مفيدة؟

المحلول

If your app is killed due to memory pressure then you will be re-launched fresh. This is certain.

If you want to restore your state in that case it's up to you.

You can use the state restoration facilities built into iOS 6. I haven't used them yet so I don't have specific tips for you.

You need some way to save your navigation state (modal VC that are on-screen and/or navigation stack) as well as the state data for each VC that's on-screen) plus any global application state data.

نصائح أخرى

UIApplication Protocol reference

https://developer.apple.com/library/ios/documentation/uikit/reference/UIApplicationDelegate_Protocol/Reference/Reference.html#jumpTo_9

delegate method didFinishLaunchingWithOptions is called when application restarts

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top