获取手机的电池信息
2017-12-05 本文已影响16人
移动端_小刚哥
1、获取电池电量
/**
获取设备电量
@return 电量百分比
*/
+ (CGFloat)getBatteryQuantity
{
[[UIDevice currentDevice] setBatteryMonitoringEnabled:YES];
return [[UIDevice currentDevice] batteryLevel];
}
2、获取电池状态
/**
获取电池状态
@return 电池状态 UIDeviceBatteryStateUnknown:无法取得充电状态情况
UIDeviceBatteryStateUnplugged:非充电状态
UIDeviceBatteryStateCharging:充电状态
UIDeviceBatteryStateFull:充满状态(连接充电器充满状态)
*/
+ (UIDeviceBatteryState)getBatteryStauts
{
[[UIDevice currentDevice] setBatteryMonitoringEnabled:YES];
return [UIDevice currentDevice].batteryState;
}