xcode - How do I detect if the charger is plugged in or unplugged using Swift? -


this question has answer here:

i want detect when charger plugged , when becomes unplugged. want write using swift. great if share code snippet it, if can tell me use nice.

see this doc more info.

swift:

uidevice.currentdevice().setbatterymonitoringenabled(true) if uidevice.currentdevice().batterystate() == uidevicebatterystatecharging {       nslog("device charging.") } 

Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -