Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get battery status?

How do I get the battery status on an iPhone?

like image 655
Raviprakash Avatar asked Dec 01 '08 10:12

Raviprakash


People also ask

How do I display battery status bar?

1 Open Settings. 2 Tap Notifications. 3 Tap on Status bar. 4 Tap on the Show battery percentage switch to display or hide the battery percentage.

How do I make my iPhone 13 battery percentage show permanently?

Go to Settings > Battery, then turn on Battery Percentage. On an iPhone with Face ID, the battery percentage appears inside the battery symbol on the status bar. Tip: On iPhone models with Face ID, you can also swipe down from the top-right corner to quickly view the battery percentage in Control Center.


1 Answers

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 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.

like image 62
Paresh Thakor Avatar answered Oct 21 '22 04:10

Paresh Thakor