在我的 iPhone 应用程序中,需要知道 iPhone 是否正在充电?
如果它正在充电,那么我想显示相同的警报。
那么如何检测 iPhone 是否在充电呢?
在我的 iPhone 应用程序中,需要知道 iPhone 是否正在充电?
如果它正在充电,那么我想显示相同的警报。
那么如何检测 iPhone 是否在充电呢?
[[UIDevice currentDevice] setBatteryMonitoringEnabled:YES];
if ([[UIDevice currentDevice] batteryState] != UIDeviceBatteryStateUnplugged) {
//Device is connected (charging or fully charged)
}
编辑:如果您想检查设备是否正在充电(还没有 100% 充满),请UIDeviceBatteryStateCharging
在 if 语句中使用常量。有关更多信息,请参阅文档。