How do I get the battery status on an iPhone?
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With