2

In my iPhone app, there is a requirement to know whether the iPhone is charging or not?

If it is charging then I want to display alert for the same.

So how can I detect whether the iPhone is charging or not?

halfer
  • 19,824
  • 17
  • 99
  • 186
Parth Bhatt
  • 19,381
  • 28
  • 133
  • 216

1 Answers1

4
[[UIDevice currentDevice] setBatteryMonitoringEnabled:YES];

if ([[UIDevice currentDevice] batteryState] != UIDeviceBatteryStateUnplugged) {
    //Device is connected (charging or fully charged)
}

Edit: If you relly want to check if the device is charging (and not 100% full yet), use the UIDeviceBatteryStateCharging constant in the if statement. See the documentation for more information.

Björn Marschollek
  • 9,899
  • 9
  • 40
  • 66