Created
March 2, 2010 01:33
-
-
Save samchandra/319029 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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