Skip to content

Instantly share code, notes, and snippets.

@BlackMac
Created December 1, 2009 12:07
Show Gist options
  • Save BlackMac/246247 to your computer and use it in GitHub Desktop.
Save BlackMac/246247 to your computer and use it in GitHub Desktop.
UIDevice *myIphone=[UIDevice currentDevice];
myIphone.batteryMonitoringEnabled=YES;
float level=myIphone.batteryLevel;
UIDeviceBatteryState state = myIphone.batteryState;
myIphone.batteryMonitoringEnabled=NO;
NSString *statusText=@"";
switch (state) {
case UIDeviceBatteryStateUnknown:
statusText=@"status unknown";
case UIDeviceBatteryStateUnplugged:
statusText=@"iPhone unplugged";
case UIDeviceBatteryStateCharging:
statusText=@"battery charging";
case UIDeviceBatteryStateFull:
statusText=@"battery full";
}
NSLog(@"Battery level: %f (%@)", level, statusText);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment