我已经在一个名为“batteryLevel”的标签上显示了电池电量,.The代码如下所示:
batteryLevel.text = [NSString stringWithFormat:@"%0.0f%%", [UIDevice currentDevice].batteryLevel * 100]; 但是我得到了电池电量的95%,90%等等。我必须准确地显示电池电量,就像在当前的device.Is中显示的一样。有什么正确的方法可以在ios7和以前的ios版本中找到电池电量吗?请给我一个解决这个问题的方法。
发布于 2013-11-28 17:06:12
您的最佳解决方案应该始终使用您使用timer显示的值,以提供外观的准确性。
使用batteryLevel属性:
[UIDevice currentDevice].batteryLevel.有关更多细节,请访问:https://developer.apple.com/Library/ios/samplecode/BatteryStatus/Introduction/Intro.html
在上面的链接中,还使用了batteryLevel属性作为示例代码最新的版本1.2。
如果您正在使用越狱设备,您可以使用
int percent = [(SBUIController*)[objc_getClass("SBUIController") sharedInstance] displayBatteryCapacityAsPercentage];此方法在iOS 4.3+上存在,并且可能是电池医生正在使用的方法。
https://stackoverflow.com/questions/20261561
复制相似问题