有没有办法在ios7中获得正确的电池电量?

时间:2013-11-28 08:56:53

标签: iphone ios7 batterylevel

我在一个名为“batteryLevel”的标签中显示了电池电量。用于此的代码如下:

batteryLevel.text = [NSString stringWithFormat:@"%0.0f%%", [UIDevice currentDevice].batteryLevel * 100]; 

但是我的电池电量达到95%,90%等。我必须准确显示电池电量,如当前设备所示。是否有正确的方法来查找ios7和之前的ios中的电池电量版本?请给我一个解决这个问题的方法。

1 个答案:

答案 0 :(得分:0)

最佳解决方案应始终使用您使用计时器显示的值来提供外观的准确性。

使用batteryLevel属性:

 [UIDevice currentDevice].batteryLevel.

了解更多细节: https://developer.apple.com/Library/ios/samplecode/BatteryStatus/Introduction/Intro.html

来自上方链接示例代码最新版本1.2 也用于 batteryLevel 属性。

如果您使用越狱设备,则可以使用

int percent = [(SBUIController*)[objc_getClass("SBUIController") sharedInstance] displayBatteryCapacityAsPercentage];

此方法适用于iOS 4.3+,可能是Battery Doctor正在使用的方法。