Am keen to know is there any possibility in iOS through which we can know whether device is connected via a USB cable or Wallport. in other words i want my app to display whether device is charging via USB cable or a Wall port.
Asked
Active
Viewed 1,120 times
4
-
The first google result for "ios api charging": http://iosdevelopertips.com/device/display-battery-state-and-level-of-charge.html – Evan Trimboli Apr 08 '13 at 05:51
-
@EvanTrimboli That article is not relevant. OP wants to distinguish the type of charge being received (via USB, or via a wall charger). – borrrden Apr 08 '13 at 05:53
-
@Syed Have you found solution to this problem? – Abilash Bansal Sep 17 '19 at 07:13
2 Answers
3
From UIDevice Class reference
UIDeviceBatteryStateDidChangeNotification
Posted when battery state changes.
For this notification to be sent, you must set the batteryMonitoringEnabled property to YES.
You can obtain the battery state by getting the value of the batteryState property.
When you receive the notification have to check for
UIDeviceBatteryState == UIDeviceBatteryStateUnplugged
The enum
UIDeviceBatteryState
The battery power state of the device.
typedef enum {
UIDeviceBatteryStateUnknown,
UIDeviceBatteryStateUnplugged,
UIDeviceBatteryStateCharging,
UIDeviceBatteryStateFull,
} UIDeviceBatteryState;

Alex Terente
- 12,006
- 5
- 51
- 71
-
i have did this but i wanted to know whether my device is connected through USB or AC Wallport – Syed Ismail Ahamed Apr 08 '13 at 06:33
0
It's just not possible - and there's probably no good reason to depend on it.
Think of many different types of computers, switched on and off, with software installed and without, users logged in or logged out, and hundreds of different charger models, usb hubs, even screens come with usb.

Eiko
- 25,601
- 15
- 56
- 71