app-store中目前有应用程序(因此不需要越狱)告诉您:
iPhone上电池电量的确切百分比值。一世 已经尝试过Apple的官方Code Sample,虽然它告诉你iPhone何时充电和放电,但它给我的价值为5%。这些应用如何获得电池百分比的确切值?
Battery Health等应用程序显示
同一应用程序还提供有关手机充电时的以瓦为单位的充电率的信息(查看图像)和当前充电器的额定功率 。
当[UIDevice]提供的信息非常少而且几乎没有关于电池运行状况和性能的信息时,这些应用程序如何获得有关电池运行状况的详细信息。
答案 0 :(得分:5)
我已经开发出一种解决方案,可以让您在不调用任何私有API调用的情况下获取此信息(尽管我当然无法向Apple承诺批准它)。
虽然有问题的信息确实来自IOKit,但我找到了一种不依赖IOKit的方法。我的解决方案完全没有任何私有API。相反,我开发了一个名为UIDeviceListener
的组件,可以有效地从UIDevice
劫持IOKit数据。
尝试一下,我已经整理了一个简单的示例程序:https://github.com/eldoogy/PowerData
作为一个例子,这里是它检索的IOKit字典往往看起来像(注意它可能因iOS版本和设备型号,生成等而异):
{
AdapterDetails = {
Amperage = 1000;
Description = "usb host";
FamilyCode = "-536854528";
PMUConfiguration = 1000;
Watts = 5;
};
AdapterInfo = 16384;
Amperage = 1000;
AppleRawCurrentCapacity = 1279;
AppleRawMaxCapacity = 1275;
AtCriticalLevel = 0;
AtWarnLevel = 0;
BatteryData = {
BatterySerialNumber = REDACTED;
ChemID = 355;
CycleCount = 524;
DesignCapacity = 1420;
Flags = 640;
FullAvailableCapacity = 1325;
ManufactureDate = REDACTED;
MaxCapacity = 1273;
MfgData = REDACTED;
QmaxCell0 = 1350;
StateOfCharge = 100;
Voltage = 4194;
};
BatteryInstalled = 1;
BatteryKey = "0003-default";
BootBBCapacity = 52;
BootCapacityEstimate = 2;
BootVoltage = 3518;
CFBundleIdentifier = "com.apple.driver.AppleD1815PMU";
ChargerConfiguration = 990;
CurrentCapacity = 1275;
CycleCount = 524;
DesignCapacity = 1420;
ExternalChargeCapable = 1;
ExternalConnected = 1;
FullyCharged = 1;
IOClass = AppleD1815PMUPowerSource;
IOFunctionParent64000000 = <>;
IOGeneralInterest = "IOCommand is not serializable";
IOInterruptControllers = (
IOInterruptController34000000,
IOInterruptController34000000,
IOInterruptController34000000,
IOInterruptController34000000
);
IOInterruptSpecifiers = (
<03000000>,
<26000000>,
<04000000>,
<24000000>
);
IOMatchCategory = AppleD1815PMUPowerSource;
IOPowerManagement = {
CurrentPowerState = 2;
DevicePowerState = 2;
MaxPowerState = 2;
};
IOProbeScore = 0;
IOProviderClass = AppleD1815PMU;
InstantAmperage = 0;
IsCharging = 0;
Location = 0;
Manufacturer = A;
MaxCapacity = 1275;
Model = "0003-A";
Serial = REDACTED;
Temperature = 2590;
TimeRemaining = 0;
UpdateTime = 1461830702;
Voltage = 4182;
"battery-data" = {
"0003-default" = <...>;
"0004-default" = <...>;
"0005-default" = <...};
"built-in" = 1;
}
答案 1 :(得分:4)
此项目可帮助您查找电池信息。
答案 2 :(得分:3)
此类应用程序很可能使用IOKit框架,该框架在OS X上是公开的,但在iOS上是私有的(Apple不允许使用私有框架用于App Store应用程序,尽管有时在审核期间可能会忽略它)。 / p>
您可以看到示例项目here。