在我的iPhone应用程序中,需要知道iPhone是否正在充电?
如果它正在充电,那么我想要显示相同的警报。
那么如何检测iPhone是否在充电呢?
发布于 2010-12-02 19:46:38
[[UIDevice currentDevice] setBatteryMonitoringEnabled:YES];
if ([[UIDevice currentDevice] batteryState] != UIDeviceBatteryStateUnplugged) {
//Device is connected (charging or fully charged)
}编辑:如果您真的想检查设备是否正在充电(并且还没有100%充满),请在If语句中使用UIDeviceBatteryStateCharging常量。有关详细信息,请参阅the documentation。
https://stackoverflow.com/questions/4334601
复制相似问题