Our application has an SDK that detects whether the user last exited abnormally. Simply put, if the app is quit from the foreground and does not receive the willTerminate callback, and there is no crash stack, it is deemed an abnormal exit. In May of this year, the reports of abnormal exits suddenly surged. Upon investigation, we found that the application was being launched in the background, and during the SDK initialization, it was set to a foreground state, which caused users who were launched in the background to be counted as having exited abnormally in the foreground.
We want to clarify the reasons for our application's background launches. I found in the documentation that a few scenarios can cause background launches:
Background fetch
Remote notifications - Silent notifications
App prewarm
Analysis:
Our application's background modes only enable Audio, AirPlay, Picture in Picture, and Remote notifications, so the possibility of background fetch can be ruled out.
As for silent notifications, the code does not have any use cases, but we cannot rule out the possibility that the server sent a silent notification causing the launch. However, in the abnormal exit logs, we do print the launchOptions in application:didFinishLaunchingWithOptions:, but the value is empty. The documentation states that if it is a silent notification, applicationDidEnterBackground: will be called after application:didFinishLaunchingWithOptions:. We can confirm through the logs that this method was not called.
Regarding app prewarm, I see that this was introduced after iOS 15. However, the surge in abnormal exits started in May of this year and occurred only after the application was updated to a certain version. The percentage of abnormal exits for older versions did not increase, which suggests it might not be strongly correlated with the iOS system. Therefore, we cannot determine whether the app prewarm caused the application to launch in the background.
I would like to ask if there is any method to ascertain if the recent launch was due to prewarm? Or is there any way to log specific API calls to determine the reason for the background launch?
Topic:
App & System Services
SubTopic:
Core OS
Tags: