计算iOS中的电池寿命 [英] Calculating battery life in iOS

查看:138
本文介绍了计算iOS中的电池寿命的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想知道是否有超出Apple技术统计数据的参考来计算电池寿命。我已经尝试比较一些现有的电池应用程序(电池剩余电量%*苹果公司的数字),我有时候也没有提出相同的答案。还有使用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.

推荐答案

API允许您注册以接收有关电池电量更改的通知。它仅报告向上或向下增加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];

第一个通知告诉您当前状态,例如拔掉,充电或充满电。只要达到5%的增量,第二个就会被触发。

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.

在我看来,如果您给出的是5%变化的变更通知,那么准确性不是你可以很好或很快计算的东西。如果设备没有做任何事情,5%的更改可能需要很长时间。

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.

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

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.

这篇关于计算iOS中的电池寿命的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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