-1

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 ?

GuybrushThreepwood
  • 5,598
  • 9
  • 55
  • 113
  • Are you sure it's killed? If it is then the app is restarted just like it was a new start... – Wain Feb 03 '14 at 11:57
  • There seem to be two scenarios - in one the app does restart, in the other is returned to the root view. – GuybrushThreepwood Feb 03 '14 at 11:59
  • didFinishLaunchingWithOptions delegate method will be called when application restarts everytime – Dinesh Kaushik Feb 03 '14 at 12:00
  • Right thanks. Is there a way I could call a specific method in my rootViewController in this case ? – GuybrushThreepwood Feb 03 '14 at 12:03
  • you might be receiving memory warning in your delegate method but you can not handle that warning when app is in background.Save state of app in database when app enters background and write appropriate code in didFinishLaunchingWithOptions when app restarts – Dinesh Kaushik Feb 03 '14 at 12:09

2 Answers2

2

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.

Duncan C
  • 128,072
  • 22
  • 173
  • 272
1

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

Dinesh Kaushik
  • 2,917
  • 2
  • 23
  • 36