I would like to know if my app is running with an external power cable attached. Is it possible to find out this state at runtime?
An extra question: would this be able to differentiate between true USB power and those external “battery packs”?
Thank you!
Use
UIDevicepropertybatteryState:From UIDevice Docs:
As for your 2nd question. I don’t believe you can determine any difference between a battery pack and a wall charger since the above
UIDeviceBatteryStateflags are the only “states” a device battery can report. So both a battery pack and wall charger would appear as eitherUIDeviceBatteryStateChargingorUIDeviceBatteryStateFull(orUIDeviceBatteryStateUnpluggedif the battery pack is plugged in but out of juice).