How to get battery level with 1

后端 未结 5 1494
陌清茗
陌清茗 2020-12-17 17:17

How to get battery level with 1 % accuracy .

       [UIDevice currentDevice].batteryLevel

Will give battery level with accuracy of 5%. But

相关标签:
5条回答
  • 2020-12-17 17:34

    If you turn off Setting->General->Usage->Battery Percentage, Battery Doctor shows your battery level with %5 precision...So I guess that they are running some image recognition algorithm for the upper right corner of the device, where the battery percent is shown.

    0 讨论(0)
  • 2020-12-17 17:40

    Answer comes from this question:

    You can use an NSTimer to manipulate the values you show giving the appearance of accuracy. For each session the app is active, make a sample set of battery data(like the time required for battery level to fall from 100% to 95%, then 95% to 90%, and so on) and save it on the device itself. Then, use the timer to set off updated(and estimated) battery value according to the time required for the battery level to fall 5% divided by 5(assuming each percentage falls after the same interval, which will vary, but it won't be a noticeable deviation). It's true that battery life falls with time but since we adjust the timer value according to the values saved in the last session, it should continue being pretty much accurate over the life of the device.

    Edit- For the initial state, you can provide a default value depending on the iPhone model(3,3G,4,4S). Different values can be calculated for these different devices.

    0 讨论(0)
  • 2020-12-17 17:45

    Starting with iOS 8,

    [UIDevice currentDevice].batteryLevel
    

    provides 1% accuracy :)

    0 讨论(0)
  • 2020-12-17 17:49

    In iOS 8.1.x I have noticed that battery level is now reporting the exact battery level for apps now. Previously, UIDevice would report every 5%. There is nothing more for you to do in iOS 8.1.x as [UIDevice currentDevice].batteryLevel should report this automatically now.

    0 讨论(0)
  • 2020-12-17 17:53

    If you're jailbroken, you can simply use

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

    This method is present on iOS 4.3+, and is probably what Battery Doctor is using.

    0 讨论(0)
提交回复
热议问题