Hello,
How do I get the battery status on an iPhone?
Regards,
Devara Gudda
Hello,
How do I get the battery status on an iPhone?
Regards,
Devara Gudda
There is no way to do this with the Apple-documented APIs (why, I have no idea, I think this is a serious oversight by Apple).
In addition, using undocumented APIs is not just frowned upon, it’s against the terms and conditions that developers agree to when they download the SDK. If they catch your application doing it, you may well find yourself removed from the App Store.
So I think you're pretty well stuck, sorry about that.
iPhone OS 2.x has no public API for this. As announced, OS 3.0 does, so you'll have to wait till June for it.
Now that the 3.1 SDK is released look for the Getting the Device Battery State section in UIDevice's documentation. It is abunch of battery* properties.
UIDevice *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 0:
{
[BCStatus setText:NSLocalizedString(@"UnknownKey", @"")];
break;
}
case 1:
{
[BCStatus setText:NSLocalizedString(@"UnpluggedKey", @"")];
break;
}
case 2:
{
[BCStatus setText:NSLocalizedString(@"ChargingKey", @"")];
break;
}
case 3:
{
[BCStatus setText:NSLocalizedString(@"FullKey", @"")];
break;
}
}
BCStatus is uilabel.