在我的iPhone应用程序中,需要知道iPhone是否正在充电?
如果正在充电,那么我想显示相同的警报。
那么如何检测iphone是否正在充电呢?
我该怎么办?
请帮助和建议。
感谢。
答案 0 :(得分:4)
[[UIDevice currentDevice] setBatteryMonitoringEnabled:YES];
if ([[UIDevice currentDevice] batteryState] != UIDeviceBatteryStateUnplugged) {
//Device is connected (charging or fully charged)
}
编辑:如果您确实想要检查设备是否正在充电(而不是100%已满),请在if语句中使用UIDeviceBatteryStateCharging
常量。有关详细信息,请参阅the documentation。