Usage tracking. applicationDidBecomeActive AND/OR didFinishLaunchingWithOptions

StackOverflow https://stackoverflow.com/questions/23368006

  •  12-07-2023
  •  | 
  •  

Вопрос

I've been looking at some analytics frameworks for mobile apps, but as usual I am never satisfied and now I have decided to roll my own solution. I will only track a small amount of things such as launches/certain taps/session length. Not advanced like flows etc.

I noticed that most analytics use application:didFinishLaunchingWithOptions to run something like a startSession. Makes sense.

But do they don't seem to track this method applicationDidBecomeActive and I am not sure why. If the user starts a session and does something in 10 seconds, then minimises the app for a couple of minutes and later opens it again. Then it wouldn't record this new session would it? Or is there usually some code within the framework itself to distinguish events like this.

After writing this question it seems like a dumb question, since each framework can (and probably do) have way different solutions. But if anyone have dealt with this I'd love some info on best practises (or any practices).

Это было полезно?

Решение

When home button pressed and app put in multitasking menu (session still active)

-(void)applicationWillResignActive:(UIApplication*)application

After 3 minutes of inactivity in multitasking menu (not being re-opened) you can kill your session here

-(void)applicationDidEnterBackground:(UIApplication*)application

When app is re-opened use this method to compute the difference between going on background and the time your app gets reopened. If this time interval exceeds lets say 3 minutes kill the old session and create new one

-(void)applicationWillEnterForeground:(UIApplication*)application

User deletes the app from multitasking menu kill your session here

-(void)applicationWillTerminate:(UIApplication*)application
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top