Calculation of battery life in iOS

I wonder if there are links behind Apple technology for calculating battery life. I tried to compare some existing battery apps (battery% left * Apple) and sometimes I don't get the same answers. There are also statistics for using a 2G cell (unlike 3G), and I don’t see anything in Apple to use a 2G battery.

Of course, some of the applications claim to be “the most accurate” ... but I don’t see what happens if someone doesn’t have a source for very accurate statistics.

+2
source share
1 answer

The API allows you to register to receive notifications of changes in battery level. It only reports a change in increments of 5% up or down, but you can use a timer and measure the time between two changes (or the initial battery level and the first change). Here you register for notifications:

// Use this call to get the current battery level as a float // [[UIDevice currentDevice] batteryLevel] [[UIDevice currentDevice] setBatteryMonitoringEnabled:YES]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(batteryStateDidChange:) name:UIDeviceBatteryStateDidChangeNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(batteryLevelDidChange:) name:UIDeviceBatteryLevelDidChangeNotification object:nil]; 

The first notification reports the current state, for example. disconnected, charged or fully charged. The second will fire when a 5% increase is reached.

It seems to me that if all that is given to you is notification of changes with 5% changes up or down, accuracy is not something that you can calculate very well or quickly. A change of 5% can take a very long time if the device does nothing.

Maybe you can control the [[UIDevice currentDevice] batteryLevel] with a timer, however, as long as I haven't tried, I think it only updates at this 5% increment.

+17
source

Source: https://habr.com/ru/post/972473/


All Articles