xcode - How do I detect if the charger is plugged in or unplugged using Swift? -
this question has answer here:
- detect if device charging 5 answers
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
Post a Comment