【问题标题】:How to detect from an iPhone app whether the battery is in charging or not?如何从 iPhone 应用程序中检测电池是否在充电?
【发布时间】:2010-12-02 11:45:50
【问题描述】:

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

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

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

【问题讨论】:

    标签: iphone cocoa-touch ios4 iphone-sdk-4.0.1


    【解决方案1】:
    [[UIDevice currentDevice] setBatteryMonitoringEnabled:YES];
    
    if ([[UIDevice currentDevice] batteryState] != UIDeviceBatteryStateUnplugged) {
        //Device is connected (charging or fully charged)
    }
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-13
      • 1970-01-01
      • 1970-01-01
      • 2011-10-11
      • 1970-01-01
      相关资源
      最近更新 更多