We had an app in production which was reporting very high time to interact(tti) for ios 15 prewarm.
TTI = timewhenViewController is loaded – mainStartTime
mainStart time is measured inside AppDelegate.swift’s willFinishLaunchingWithOptions method like this
mainStartTime = Date()
and when first view controller is loaded we measure tti as
tti = -(mainStartTime.timeIntervalSinceNow)
We observed that for prewarm scenarios mainStartTime was coming very early (approx 2 hours before user even launches the app).
I checked online but found no documentation.
Just wanted to know can it possibly happen that prewarm is calling willFinishLaunchingWithOptions method while prewarming the app.
2
Answers
There is poor documentation about Prewarming:
But prewarming can call both
willFinishLaunchingWithOptions
anddidFinishLaunchingWithOptions
from my tests on my iPhone 13 with iOS 15.0.I’ve created a test app which logs all calls to a string array:
main.swift
AppDelegate.swift
SceneDelegate.swift
Then did the following:
My logs:
As you can see the system launched my app (prewarm) at 12:28:36 and held in background until my manual start at 12:58:15 and after gave access to protected data and loaded UI.
Apple’s documentation is incorrect, here is the behaviour observed on iOS 15:
UIApplicationMain()
always runs, including during prewarming.What happens after this depends on whether your app uses the
UIScene
life-cycle.For apps that do support scenes:
application:didFinishLaunchingWithOptions:
may be called (doesn’t always happen)scene:willConnectToSession:options:
is not called – in fact theSceneDelegate
is not created until the app is opened.For apps that do not support scenes:
application:didFinishLaunchingWithOptions:
is not called.