2

在我的 iPhone 应用程序中,需要知道 iPhone 是否正在充电?

如果它正在充电,那么我想显示相同的警报。

那么如何检测 iPhone 是否在充电呢?

4

1 回答 1

4
[[UIDevice currentDevice] setBatteryMonitoringEnabled:YES];

if ([[UIDevice currentDevice] batteryState] != UIDeviceBatteryStateUnplugged) {
    //Device is connected (charging or fully charged)
}

编辑:如果您想检查设备是否正在充电(还没有 100% 充满),请UIDeviceBatteryStateCharging在 if 语句中使用常量。有关更多信息,请参阅文档

于 2010-12-02T11:46:37.797 回答