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.
source share