检测充电器连接和电池充电状态:
- [[UIDevice currentDevice] setBatteryMonitoringEnabled:YES];
- if ([[UIDevice currentDevice] batteryState] == UIDeviceBatteryStateCharging) {
- NSLog(@"Device is charging.");
- }
UIDeviceBatteryState
The battery power state of the device.
typedef enum { UIDeviceBatteryStateUnknown, UIDeviceBatteryStateUnplugged, UIDeviceBatteryStateCharging, UIDeviceBatteryStateFull, } UIDeviceBatteryState;
Constants
-
// 未知状态
-
// 电源没有插入,未充电状态
-
// 电源插入,正在充电状态
-
// 电源插入,充电已满状态
UIDeviceBatteryStateUnknown
UIDeviceBatteryStateUnplugged
UIDeviceBatteryStateCharging
UIDeviceBatteryStateFull