I want to measure iPhone usage time (time the device is not sleeping)

Asked 1 years ago, Updated 1 years ago, 59 views

Question 1

It seems that they are measuring the usage time of the terminal.
(General>Usage>Battery Usage>Time of use)
Is it possible to get that information from the app?

Question 2

Is it possible to start the application in the background and get the time when the terminal wakes up from sleep?
Also, is it possible to get the time of sleep in the background after the terminal sleeps?

Question 3

Is there any other way to measure iPhone usage time?

Please let me know.

ios objective-c swift xcode iphone

2022-09-30 14:46

2 Answers

The NSProcessInfo systemUptime function tells you how long (in seconds) it will be used.
When you sleep, the uptime does not increase, so it seems to be the cumulative amount of time you have been running the terminal since you started it.

https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSProcessInfo_Class/index.html#//apple_ref/occ/instp/NSProcessInfo/systemUptime


2022-09-30 14:46

Is it possible to get the time when the terminal sleeps in the background after it sleeps?

Wouldn't it be possible to do this by using Background Fetch?
Application:performFetchWithCompletionHandler is called for every set time (approximate), so you may want to try to find the time difference from the time when the application started.

Search for the Background Fetch description and you'll find a lot of information.


2022-09-30 14:46

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.