Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect if device is charging

Tags:

iphone

I can't find anything definite using my favourite tool, however I thought I would put it out here...

Is there a way, using the iPhone SDK, for an app to detect if the device is in a state of receiving power (charging, dock, etc.)?

I would like to be able to disable the idleTimer automatically if the device is receiving power (otherwise it is a user-specified setting).

like image 728
adam Avatar asked May 08 '09 10:05

adam


People also ask

How do you check if a device is charging?

It's universal — when you plug in your phone you'll see a charging icon pop up. If you don't see one, it likely isn't charging. Your phone is off and it doesn't come back on. If your phone dies and doesn't come back to life when you plug it in, it's probably not getting any power.

How can I tell if my phone battery is charging?

From the Home screen, tap the Apps Key > Settings > Battery. The battery level (as a percentage of fully charged) and the battery status (Charging or Discharging) is displayed at the top of the screen.


1 Answers

You are better off using:

[[UIDevice currentDevice] setBatteryMonitoringEnabled:YES];  if ([[UIDevice currentDevice] batteryState] != UIDeviceBatteryStateUnplugged) {       [UIApplication sharedApplication].idleTimerDisabled=YES;     } 

This is because you have to concern yourself with two different states - one is that the battery is charging, and the other when it is fully charged.

If you really wanted to be complete about it - you would register to receive battery monitoring notifications, so you could re-enable the idle timer if the user disconnected main power, etc.

like image 55
Brad Avatar answered Sep 28 '22 05:09

Brad