4

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.

Syed Ismail Ahamed
  • 349
  • 1
  • 6
  • 17

2 Answers2

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
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