iOS - 电池
作者:
CDLOG | 来源:发表于
2018-08-16 16:59 被阅读2次//根据电池情况判断是否执行操作
-(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;
}
本文标题:iOS - 电池
本文链接:https://www.haomeiwen.com/subject/eeyobftx.html
网友评论