Skip to content

Instantly share code, notes, and snippets.

@samchandra
Created March 2, 2010 01:33
Show Gist options
  • Save samchandra/319029 to your computer and use it in GitHub Desktop.
Save samchandra/319029 to your computer and use it in GitHub Desktop.
- (BOOL) isPowerConnected
{
// Temporarily enable battery monitoring to check battery state
[UIDevice currentDevice].batteryMonitoringEnabled = YES;
BOOL result = ([UIDevice currentDevice].batteryState != UIDeviceBatteryStateUnplugged);
[UIDevice currentDevice].batteryMonitoringEnabled = NO;
return result
}
// Use this in another method
if (isPowerConnected)
{
// Do something here which only work when the power is connected.
// For example disable idle timer only when connected to power
[UIApplication sharedApplication].idleTimerDisabled = YES;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment