iOS - 电池

2018-08-16  本文已影响2人  CDLOG
//根据电池情况判断是否执行操作
-(BOOL)shouldProcessWithMinLevel:(NSInteger )minLevel{
    UIDevice *device = [UIDevice currentDevice];
    [device setBatteryMonitoringEnabled:YES];
//在充电或者充满
    UIDeviceBatteryState state = device.batteryState;
    if (state == UIDeviceBatteryStateCharging || state == UIDeviceBatteryStateFull) {
        return YES;
    }
//拿到电池的当前电量
    NSInteger batteryLevel = (NSInteger)(device.batteryLevel*100);
  //   在最低限制以上
    if (batteryLevel>=minLevel) {
        return YES;
    }
    return NO;
    
}
上一篇 下一篇

猜你喜欢

热点阅读