如何在iOS上获得1%粒度的实时电池电量 [英] How to get real time battery level on iOS with a 1% granularity

查看:126
本文介绍了如何在iOS上获得1%粒度的实时电池电量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用此函数获取设备的当前电池电量:

I'm using this function to get current battery level of device:

[[UIDevice currentDevice] setBatteryMonitoringEnabled:YES];
UIDevice *myDevice = [UIDevice currentDevice];

[myDevice setBatteryMonitoringEnabled:YES];
double batLeft = (float)[myDevice batteryLevel]; 
NSLog(@"%f",batLeft);

但结果具有5%的粒度。示例:当手机电池电量为88%时,它仅记录0.85的值。 batteryLevel 只返回以0.05为增量的值。例如:0.85,0.9,0.95,从不返回值如0.82或0.83。

but the result has a 5% granularity. Example: when the phone battery is at 88%, it only logs a value of 0.85. batteryLevel only returns values in increments of 0.05. For example: 0.85, 0.9, 0.95 and never returns values like 0.82 or 0.83.

有任何解决方案可以获得更高精度的百分比吗?

Is there any solution to get a percentage with a higher precision?

推荐答案

请查看此网站:
以编程方式阅读电池电量

,但请小心使用。这里使用的所有API都没有在iPhone上记录,如果您将此应用程序提交到App Store,可能会导致拒绝。虽然电池充电状态不完全,我建议使用UIDevice电池监控方法。

but, carefully use. all of the APIs used here are undocumented on the iPhone, and will probably lead to a rejection if you submit this application to the App Store. Although battery charge status is not exactly, I'd recommend using the UIDevice battery monitoring methods.

这篇关于如何在iOS上获得1%粒度的实时电池电量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆