【问题标题】:How do I detect if the charger is plugged in or unplugged using Swift? [duplicate]如何使用 Swift 检测充电器是插入还是拔出? [复制]
【发布时间】:2015-10-10 02:55:13
【问题描述】:

我想检测充电器何时插入以及何时拔出。我想用 Swift 写这个。如果有人分享它的代码 sn-p 那就太好了,但如果你能告诉我使用什么就很好了。

【问题讨论】:

  • 上面给出的重复答案是目标而不是 Swift。

标签: xcode swift ios9


【解决方案1】:

请参阅This doc 了解更多信息。

Swift:

UIDevice.currentDevice().setBatteryMonitoringEnabled(true)
if UIDevice.currentDevice().batteryState() == UIDeviceBatteryStateCharging {
      NSLog("Device is charging.")
}

【讨论】:

    猜你喜欢
    • 2018-02-08
    • 2011-05-12
    • 1970-01-01
    • 2017-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-14
    • 2012-12-26
    相关资源
    最近更新 更多