I had the same warning before and fixed it by doing the followings.
I was using storyboard. My storyboard only included a navigation view controller and a view controller (which was the root view controller of that navigation view controller). In my case, it was caused by either of the two reasons:
The application was not set up correctly for state preservation
The followings need to be set:
In app delegate, override application:willFinishLaunching. One can simply return YES in that method.
For every view controllers and views (including the navigation view controllers and tab view controllers), set a restore ID
In app delegate, opt-in by overriding shouldSaveApplicationState
and shouldRestoreApplicationState
If this warning still occurred, you could check how you run your app in Xcode. I ran my app in Xcode simulator and had to follow a specific sequence to trigger state preservation.
- launch the app in Xcode simulator
- In Xcode simulator, click the "Home" button to put the app into the background. The
encodeRestorableStateWithCoder
method of the view controller should be called
- go back to Xcode, click the "stop" button to terminate the simulation
- In Xcode simulator, double click the "Home" button and then remove the app from the app switcher and
- go back to Xcode, run the app again.
That warning should not appear. When I used other sequences, I saw that warning appearing. When I debugged my app on my device using Xcode, I followed the same sequence and did not see the warning.
I think that warning indicated that because Xcode could not terminate the app correctly, the state restoration file was not correctly saved onto the disk.