Why is applicationWillEnterForeground called on first launch when using AppIntent with openAppWhenRun = true?

Hello,

I’ve implemented a feature in my app using AppIntent. When the app is not running in the background and is launched for the first time via a shortcut, both application:didFinishLaunchingWithOptions: and applicationWillEnterForeground: are called.

Normally, on the first launch, applicationWillEnterForeground: is not invoked. However, this behavior seems to occur only when the app is launched through a shortcut.

I’d like to understand why applicationWillEnterForeground: is being called in this scenario.

For reference, the AppIntent has openAppWhenRun set to true.

Thank you in advance for your help!

If your app is not already running, the system will launch your app in the background to run an app intent. Not all app intents require the app to be brought to the foreground, so your app's lifecycle implementation should be making sure that you can support a background launch without any assumptions that your app will have scene UI visible.

For those app intents that have openAppWhenRun set to true, a scene is created and displayed as part of the execution of your intent, but that is after the creation and launch of your app into the background is complete. That is why your app receives delegate callbacks that it is transitioning into the foreground.

I see also that you are naming applicationWillEnterForeground: as the method involved, instead of sceneWillEnterForeground. You should invest in adopting the scene-based lifecycle as the current best practice for managing your app's lifecycle, even if your app only needs a single scene. Specifying the scenes your app supports explains how you can do that.

—Ed Ford,  DTS Engineer

Why is applicationWillEnterForeground called on first launch when using AppIntent with openAppWhenRun = true?
 
 
Q