计算 iOS 中的电池寿命

发布于 2024-08-06 05:21:31 字数 210 浏览 4 评论 0原文

想知道除了苹果技术统计数据之外是否还有其他参考资料来计算电池寿命。我尝试比较一些现有的电池应用程序(剩余电池百分比*苹果的数据),但有时我没有得出相同的答案。另外还有使用 2G 电池(而不是 3G)的统计数据,我在 Apple 上没有看到任何关于 2G 电池寿命的信息。

当然,一些应用程序声称它们是“最准确的”......但除非有人拥有非常准确的统计数据来源,否则我不会看到这种情况发生。

Wondering if there are references beyond the Apple tech stats for calculating battery life. I've tried comparing some existing battery apps (battery % left * Apple's figures) and I dont come up with the same answers sometimes. Also there are stats for using 2G cell (as opposed to 3G) and I dont see anything on Apple for 2G battery life.

Of course, some of the apps claim they are 'the most accurate'... but I dont see that happening unless someone has a source for very accurate stats.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

牵强ㄟ 2024-08-13 05:21:31

该 API 允许您注册以接收电池电量变化的通知。它仅报告向上或向下 5% 增量的变化,但您可以使用计时器并测量两次变化之间的时间(或初始电池电量和第一次变化)。以下是注册通知的方法:

// Use this call to get the current battery level as a float
// [[UIDevice currentDevice] batteryLevel]

[[UIDevice currentDevice] setBatteryMonitoringEnabled:YES];

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(batteryStateDidChange:)
                                             name:UIDeviceBatteryStateDidChangeNotification
                                           object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(batteryLevelDidChange:)
                                             name:UIDeviceBatteryLevelDidChangeNotification
                                           object:nil];

第一个通知告诉您当前状态,例如已拔出、正在充电或已充满。当增量达到 5% 时,第二个就会被触发。

在我看来,如果您收到的只是 5% 的上下变化通知,那么准确性就不是您可以很好或快速计算的东西。如果设备不执行任何操作,5% 的更改可能需要很长时间。

也许您可以使用计时器监视 [[UIDevice currentDevice] BatteryLevel],但是,虽然我还没有尝试过,但我认为它只会以同样的 5% 增量更新。

The API allows you to register to receive notifications for changes to the battery level. It only reports a change at 5% increments up or down, but you can use a timer and measure the time between two changes (or initial battery level and first change). Here's how you register for the notifications:

// Use this call to get the current battery level as a float
// [[UIDevice currentDevice] batteryLevel]

[[UIDevice currentDevice] setBatteryMonitoringEnabled:YES];

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(batteryStateDidChange:)
                                             name:UIDeviceBatteryStateDidChangeNotification
                                           object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(batteryLevelDidChange:)
                                             name:UIDeviceBatteryLevelDidChangeNotification
                                           object:nil];

The first notification tells you the current state, e.g. unplugged, charging, or full. The second will get triggered whenever a 5% increment is reached.

Seems to me that if all you're given is change notifications at 5% changes up or down, accuracy is not something you can calculate very well or quickly. A 5% change could take a very long time if the device isn't doing anything.

Maybe you can monitor [[UIDevice currentDevice] batteryLevel] with a timer, however, while I haven't tried it I think it only gets updated at this same 5% increment.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文