How to get battery level with 1

后端 未结 5 1497
陌清茗
陌清茗 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: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.

提交回复
热议问题