如何使用iOS 7获得完美的iPhone电池百分比

per*_*tta 2 iphone tweak jailbreak ios7

我是stackoverflow的新手.我在很多网站上搜索了这个问题的解决方案,但我还没有发现任何完整的问题.我的问题是如何在iPhone上获得电池的百分比值,精确度为1%.我知道使用越狱设备是可能的,但是怎么样?我的代码在下面,但它返回值0.

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

batteryLabel.text = [NSString stringWithFormat: @"Battery is at %0.0f", percent];
Run Code Online (Sandbox Code Playgroud)

Ada*_*ght 5

看一下:

[UIDevice currentDevice].batteryMonitoringEnabled = YES;
return [NSString stringWithFormat: @"Battery is at %0.0f", [UIDevice currentDevice].batteryLevel * 100];
Run Code Online (Sandbox Code Playgroud)