I am monitoring for battery events UIDeviceBatteryLevelDidChangeNotification
and UIDeviceBatteryStateDidChangeNotification
. I am looking specifically for 20% and 10%, however, I am seeing these events fire off at 23%, 13% which they should be hitting at 0.05 intervals or every 5%.
Question
Does anyone else experience this, or is there a better way to ensure the levels are more accurate?
Example
-(void)startMonitoringForBatteryChanges
{
// Enable monitoring of battery status
[[UIDevice currentDevice] setBatteryMonitoringEnabled:YES];
// Request to be notified when battery charge or state changes
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkBatteryStatus) name:UIDeviceBatteryLevelDidChangeNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkBatteryStatus) name:UIDeviceBatteryStateDidChangeNotification object:nil];
}
- (void)checkBatteryStatus
{
float warningLevel = [[UIDevice currentDevice] batteryLevel] * 100;
if ( warningLevel == 20.0 ) // 20%
{
NSLog(@"20% Warning.");
}
if ( warningLevel == 10.0 ) // 10%
{
NSLog(@"10% Warning.");
}
}