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

html - Difficulties with background-image property -

visual studio code - What does the isShellCommand property actually do and how should you use it? -

ios - Segue not passing data between ViewControllers -