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).
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With