电量低于 <= 50 %进行报警
name:NSProcessInfoPowerStateDidChangeNotification
UIDeviceBatteryLevelDidChangeNotification
[[NSNotificationCenter defaultCenter]
addObserverForName:UIDeviceBatteryLevelDidChangeNotification
object:nil queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification *notification) {
// Level has changed
[UIDevice currentDevice].batteryMonitoringEnabled = YES;
NSLog(@"Battery Level Change");
NSLog(@"电池电量:%.2f", [UIDevice currentDevice].batteryLevel);
}];
UIDeviceBatteryStateDidChangeNotification
一、电池状态获取及监测code
#pragma mark - 电池状态获取及监控
-(void)checkAndMonitorBatteryState{
UIDevice * device = [UIDevice currentDevice];
//是否允许监测电池
//要想获取电池状态和监控电池状态 必须允许
device.ba
了解本专栏
订阅专栏 解锁全文