Search code examples
iphoneios7jailbreaktweak

How to obtain the perfect % of the battery of an iPhone with iOS 7


I'm new on stackoverflow. I've searched on so many sites for a solution to this question but I haven't found anything complete. My question is how can I obtain the percent value of the battery on an iPhone with the accuracy of 1%. I know that it's possible with a jailbroken device, but how? My code is below but it returns a value of 0.

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

batteryLabel.text = [NSString stringWithFormat: @"Battery is at %0.0f", percent];

Solution

  • From libMobileGestalt.dylib

    CFPropertyListRef MGCopyAnswer(CFStringRef property)
    
    MGCopyAnswer(CFSTR("BatteryCurrentCapacity"))
    

    Works even in AppStore app on my jailbroken phone.

    UPDATE

    batteryLabel.text = [NSString stringWithFormat: @"Battery is at %@", MGCopyAnswer(CFSTR("BatteryCurrentCapacity"))];