How do I get the battery status on an iPhone?
See Question&Answers more detail:osUIDevice *myDevice = [UIDevice currentDevice];
[myDevice setBatteryMonitoringEnabled:YES];
float batLeft = [myDevice batteryLevel];
int i=[myDevice batteryState];
int batinfo=(batLeft*100);
NSLog(@"Battry Level is :%d and Battery Status is :%d",batinfo,i);
switch (i)
{
case UIDeviceBatteryStateUnplugged:
{
[BCStatus setText:NSLocalizedString(@"UnpluggedKey", @"")];
break;
}
case UIDeviceBatteryStateCharging:
{
[BCStatus setText:NSLocalizedString(@"ChargingKey", @"")];
break;
}
case UIDeviceBatteryStateFull:
{
[BCStatus setText:NSLocalizedString(@"FullKey", @"")];
break;
}
default:
{
[BCStatus setText:NSLocalizedString(@"UnknownKey", @"")];
break;
}
}
BCStatus is uilabel.