我正在监视电池事件UIDeviceBatteryLevelDidChangeNotification
和UIDeviceBatteryStateDidChangeNotification
. 我专门寻找20%和10%,但是,我看到这些事件以 23% 和 13% 触发,它们应该以0.05间隔或每5%触发。
问题
有没有其他人遇到过这种情况,或者有没有更好的方法来确保水平更准确?
例子
-(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.");
}
}