监听电池电量

#pragma电池电量

//需要开启电量监听默认为no

myDevice.batteryMonitoringEnabled=YES;

//huoqu电池的状态

switch(myDevice.batteryState) {

caseUIDeviceBatteryStateUnknown:

NSLog(@"电池的状态未知");

break;

caseUIDeviceBatteryStateCharging:

NSLog(@"电池正在充电");

break;

caseUIDeviceBatteryStateUnplugged:

NSLog(@"电池未充电");

break;

caseUIDeviceBatteryStateFull:

NSLog(@"电池电量充满");

break;

default:

break;

}

//获取当前电池的电量

NSLog(@"当前电池的电量百分比是%3.0f%%",([myDevicebatteryLevel]) *100);

你可能感兴趣的:(监听电池电量)