本文介绍了如何获取电池状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在iPhone上获取电池状态?
How do I get the battery status on an iPhone?
推荐答案
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为uilabel。
BCStatus is uilabel.
这篇关于如何获取电池状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!