简体   繁体   中英

When in iOS applicationDidEnterBackground called immediately after applicationDidBecomeActive?

in our app we are logging (with an external analytics service) every time the user open our app. However, we have noticed that there are many weird app sessions (almost 15% of total sessions).

Following the device timestamp of the events, the following methods are called:

application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?)

applicationDidBecomeActive(_ application: UIApplication)

viewDidAppear(_ animated: Bool) // App Splash Screen

applicationDidEnterBackground(_ application: UIApplication)

Looking at the timestamp, from didFinishLaunchingWithOptions to applicationDidEnterBackground there is just a very short delay (<1 sec).

Our hypothesis is that the system sometimes wakes up the app without it being actually opened and "seen" by the user. But we can't find any docs about this kind of use case, and we can't reproduce ourself the issue. Did someone have experienced something similar?

EDIT : I want to add that these suspicious sessions are often (but not always) linked to an app update.

I'm not sure...

I suppose if app wasn't user terminated nor suspended but was just put out of memory because other apps needed the memory, then almost a launch options can wake the app up if needed. Some examples:

Take a look at here and see what launch options are possible for your app. I'm not sure if all of them can actually launch the app or what...

If you want more visibility into this, then make sure for future you log the launchoptionskey that caused the app to get launched...

You need more info - I would extend your logging to dump the launchOptions dictionary in

application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?)

Looking at UIApplication.LaunchOptionsKey , there are a lot of options which may be involved. Note, as the help says: The contents of this dictionary may be empty in situations where the user launched the app directly

 if let lop = launchOptions { 
   let toLog = lop.map{"\($0.0.rawValue) \($0.1)"}.joined(separator:"\n")
   // log the options
...}

I did have an idea this might be related to previewing in AppSwitcher but that doesn't seem to trigger didFinishLaunchingWithOptions , unless you actually bring the app to the front. Maybe some split-screen stuff on iPad? It feels like the app is being invoked in a context where it can't get past the launch screen.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM