App terminates with the error: UIWindows were created prior to initial application activation

Sometimes (let's say once every 10-20 tries) when application is sent to background by pressing the home button and launched real quick again, the following error is seen on the console:

UIWindows were created prior to initial application activation. This may result in incorrect visual appearance.

And subsequently the app gets the call applicationWillTerminate: and is terminated. There is no crash or any type of crash log. It seems the system terminated the app.

Here are some of the application delegate calls around this time:

================================

default 10:20:49.118688-0700 App applicationDidEnterBackground:

default 10:20:49.128036-0700 App applicationDidEnterBackground: saved managed object context

error 10:20:49.683527-0700 App UIWindows were created prior to initial application activation. This may result in incorrect visual appearance.

default 10:20:49.689023-0700 App applicationWillEnterForeground:

default 10:20:50.358051-0700 App applicationDidEnterBackground:

default 10:20:50.360120-0700 App applicationDidEnterBackground: saved managed object context

default 10:20:50.363996-0700 ToDo applicationWillTerminate:

================================

Even though it's not impacting the app functionally except that once in a while the user may have to re-launch the app, still, it can lower user confidence in the app. How can I prevent this? Is there anything that should be done in the application lifecycle via one of those delegate calls?

Thanks.

The message "UIWindows were created prior to initial application activation" is not indicative of a problem per se, but since the windows were created before UIKit knew the scene geometry, the windows may be of the incorrect size . This log also only occurs if you have not adopted the scene based life cycle in your application (if you did, the windows would not be presented until you explicitly move them to a scene).

Do you support state restoration in this app? There is a case where if the application is launching, but the state restoration archive cannot be read (usually because the device is locked) then we'll terminate the app instead of continuing (I think because continuing would destroy the state restoration archive). Could this be what you are hitting?

If you can take a backtrace when applicationWillTerminate is called, then I can confirm.

Ok, I'll look into that. It's not always reproducible. I am using core data and hence initializing data controller/persistent container. And I do read the data to initialize certain state. Is that what you meant by state restoration archive? If that is the case, I hit it even though device is not locked. I just keep swiping the app off and then relaunch. And sometimes it'd terminate upon launch with the warnings mentioned above.

App terminates with the error: UIWindows were created prior to initial application activation
 
 
Q