0

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

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

但是我得到了 95%、90% 等的电池电量。我必须准确地显示电池电量,就像在当前设备中显示的那样。在 ios7 和以前的 ios 版本中有没有正确的方法来找出电池电量?请给我一个解决这个问题的方法。

4

1 回答 1

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 正在使用的方法。

于 2013-11-28T09:06:11.520 回答