How to determine if a cold start is a background launch when using SceneDelegate (scene-based lifecycle)

  • (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { if (application.applicationState == UIApplicationStateBackground) { // ✅ Background launch } else { // ✅ Normal foreground launch }

} Previously, when using AppDelegate to handle lifecycle methods, I could determine whether a cold start was a background launch as shown above. This allowed me to accurately measure cold start time for real-world users.

The platform now requires migration to scene-based lifecycle management by iOS 16. However, after migration:

In both application:didFinishLaunchingWithOptions: and scene:willConnectToSession:options: methods,

application.applicationState == UIApplicationStateBackground and scene.activationState == UISceneActivationStateUnattached These values remain fixed regardless of whether it's a background launch, making them unusable for differentiation.

I attempted to use information from UISceneConnectionOptions for distinction but found it ineffective.

Question: Are there alternative approaches to achieve this distinction?

Answered by DTS Engineer in 846485022

Before you go any further I'll suggest you review Respond to scene-based life-cycle events. It goes over the various state transitions for scenes.

That said, your App lifecycle and Scene lifecycle mean slightly different things and you should pay attention to that because you app can have a single or multiple scene and each scene has its own life cycle, each can be in a different state of execution.

When you or the system requests a new scene for your app, UIKit creates it and puts it in the unattached state

UIKit can also disconnect a background or suspended scene at any time to reclaim its resources, returning that scene to the unattached state.

Accepted Answer

Before you go any further I'll suggest you review Respond to scene-based life-cycle events. It goes over the various state transitions for scenes.

That said, your App lifecycle and Scene lifecycle mean slightly different things and you should pay attention to that because you app can have a single or multiple scene and each scene has its own life cycle, each can be in a different state of execution.

When you or the system requests a new scene for your app, UIKit creates it and puts it in the unattached state

UIKit can also disconnect a background or suspended scene at any time to reclaim its resources, returning that scene to the unattached state.

How to determine if a cold start is a background launch when using SceneDelegate (scene-based lifecycle)
 
 
Q