3

How do we measure device usage through an app? I see apps like moment keeping track of how much the phone was in use in last 24 hours (as total screen time). Is there an API from iOS SDK or infer through certain signals in iOS?

Basically want to able to answer - how long have you used (including but not limited to calls, imessages, apps, games) your phone today? I am happy to infer it but need to know what signals to look for.

xoail
  • 2,978
  • 5
  • 36
  • 70
  • 1
    Do you want to measure usage of the entire device? or just usage of your app on a specific device? What kind of data are you trying to gather? – Michael Dautermann Aug 16 '17 at 18:45
  • Entire device or phone – xoail Aug 16 '17 at 18:45
  • Good question and interesting app. Check [this](https://stackoverflow.com/a/39281076/1040347) answer for getting current running application and also [that](https://stackoverflow.com/a/28373247/1040347) answer to make your app run constantly using [Location Services](https://stackoverflow.com/a/19043297/1040347). – Aleksey Potapov Aug 16 '17 at 18:55
  • @AlekseyPotapov not sure if that is relevant but thanks for suggesting, learnt something new. – xoail Aug 16 '17 at 19:00
  • But this kind of application will just significantly reduce battery life. – Aleksey Potapov Aug 16 '17 at 19:02

1 Answers1

2

This is answered in the FAQ of the Moment app:

To automatically track your screen time, Moment must be running in the background. Apple only allows apps to run consistently in the background in very specific use cases. Tracking the places you go is one of those, which allows Moment to run in the background.

The app registers itself as a Location Service so that its code can still run in background, until the device is locked. Whenever the code is still running, it can be counted towards the usage time.

It may also use other background modes to improve reliability to stay in background, but you'll never know the exact mechanism unless you unpack their IPA.

kennytm
  • 510,854
  • 105
  • 1,084
  • 1,005
  • Still not sure how they can infer usage per day like that. How does running in background help gather info when I am not actively using my app but other apps? Unless that is part of background running task API which creates an event when phone is unlocked even if my app is not active. – xoail Aug 16 '17 at 19:08
  • @xoail: You use sampling. Run the background code every 5 minutes and see what apps are running in the front (see Aleksey's comment). If the same app appeared consecutively within that interval, it is highly likely that the user used that app for 5 minutes in that period. – kennytm Aug 16 '17 at 20:57
  • I have check Aleksey's comment and the solution in the link only show app made by yourself, not every app on the device. Could send me another link on how to see what apps are running in the front? – Hien Pham Nov 11 '21 at 07:55