didFinishLaunchingWithOptions is called in background

Hello,

Based on the application runtime logs, after switching to the background (possibly due to the user forcibly closing the application), the app sometimes restarts immediately or after several seconds and executes the didFinishLaunchingWithOptions method (at this point, UIApplicationState == UIApplicationStateBackground).

The application itself has not requested background permissions, as shown in the attachment. I am puzzled about what could cause the application to restart in the background several seconds after being forcibly closed.

Could you please help clarify the possible reasons for this behavior?

(We have considered if it might be due to prewarming, but there is no prewarm flag during the startup.)

Thank you.

I don't know what you mean the application has not requested background execution. As seen there you have obviously declared Remote Notifications background capability.

If you are sending push notifications with the content-available:1 entry in the payload, this will have the ability to launch the app if it is not running at the time (except for if user has terminated it, then it will never launch).

That is one possible explanation. Whatever it is, it is likely something you are doing in the app, and not prewarming or some other system function.

I also see you are using NFC functionality. Is your app supporting background tag reading? If so, and the app is not running, then didFinishLaunchingWithOptions() will be called before application(_:continue:restorationHandler:) is called

Are you not checking the UIApplication.LaunchOptionsKey in didFinishLaunchingWithOptions()? That should explain why your app is being launched.


Argun Tekant /  DTS Engineer / Core Technologies

thank you for reply。

I am sure not using content-available:1 in payload with push notifications。 also our App offers NFC functionality, but it has very few users. from the log,users terminate the app and then didFinishLaunchingWithOptions was called immediately。

I think something was doing in the App, but we have not find them。 the runtime logs from the real user, and i can not reproduce it,and i will log LaunchOptions to find if if has something usefully.

The phenomenon is that after the app is terminated, a cold start is immediately triggered in the background. if have more informations, thank you for sharing it.

With the limited information I have, I don't have more guesses. But if you get logs of the launch options, do share them here.

I would also suggest to make sure your logging for the events are correct. Once the user terminates an app, in most cases the system will not relaunch that app again except under rare circumstances. Also, unless your app is actively running at the time of the termination, you would have no feedback in the app that it has been terminated. So, I am wondering how are you determining the user has terminated the app.

didFinishLaunchingWithOptions is called in background
 
 
Q