views:

1653

answers:

7

Hello,

How do I get the battery status on an iPhone?

Regards,

Devara Gudda

A: 

I don't believe there's a way to do this using the SDK.

Ben Gottlieb
A: 

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.

paxdiablo
A: 

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.

Mike Abdullah
+2  A: 

Iphone SDK 3.0 beta supports this.

Devara Gudda
Though that information might be covered by the NDA...
Stephen Darlington
...and then again, it might have been announced by Apple in a public forum.
Roger Nolan
A: 

And how do you do it without SDK ? whats the API ?

A: 

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.

Grzegorz Adam Hankiewicz
What the bump?™
Henri Watson
A: 

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.

MobiHunterz