【发布时间】:2010-12-02 11:45:50
【问题描述】:
在我的 iPhone 应用中,需要知道 iPhone 是否正在充电?
如果它正在充电,那么我想显示同样的警报。
那么如何检测 iPhone 是否在充电呢?
【问题讨论】:
标签: iphone cocoa-touch ios4 iphone-sdk-4.0.1
在我的 iPhone 应用中,需要知道 iPhone 是否正在充电?
如果它正在充电,那么我想显示同样的警报。
那么如何检测 iPhone 是否在充电呢?
【问题讨论】:
标签: iphone cocoa-touch ios4 iphone-sdk-4.0.1
[[UIDevice currentDevice] setBatteryMonitoringEnabled:YES];
if ([[UIDevice currentDevice] batteryState] != UIDeviceBatteryStateUnplugged) {
//Device is connected (charging or fully charged)
}
编辑:如果您想检查设备是否正在充电(还没有 100% 充满),请在 if 语句中使用 UIDeviceBatteryStateCharging 常量。请参阅the documentation 了解更多信息。
【讨论】: