我想知道是否可以接收有关电池的信息,如:容量(mA),电压(V),iOS内的循环次数?
我知道UIDevice类,但电池电量不是我想要的。
我可能错了,但使用公共API这是不可能的。根据UIDevice
文档,您可以做的最多就是获得电池充电水平,状态,并启用电池监控。
更新2019年2月15日:看起来iOS UIDevice
API现在允许开发人员访问设备的电池电量级别。的whooo!它目前公开了4种不同的API。从它的外观来看,它们不是“私有的”,换句话说,开发人员可以安全地使用,而Apple没有从AppStore阻止你的应用程序。
获取设备电池状态
var batteryLevel: Float
(设备的电池电量)。var isBatteryMonitoringEnabled: Bool
(一个布尔值,表示电池监控是否启用(true)或不启用(false))。var batteryState: UIDevice.BatteryState
(设备的电池状态)。enum UIDevice.BatteryState
(设备的电池电量状态)。尝试UIDeviceListener,它基本上从UIDevice
窃取整个电池数据字典,而不使用任何私有API。它暴露了大量的信息:
{
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;
}
它可以使用公共API获取电池容量和电压,并允许在应用商店中使用。链接在这里 -
是的,可以使用私有框架iosDiagnosticsupport.Framework。 在做了一些测试后,我有一些关于电池的数据而不是iDevice的整体日志。以下是一些可能对您有帮助的链接... iOS Diagnostics Part 3
看看JSystemInfoKit图书馆。
您想首先导入IOKit框架(从此处获取.framework文件/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/IOKit.framework )和iOS项目中的IOKit头文件(从here获取这些文件)。
Here你可以找到你需要用来获取大量电池信息的方法。
另外,IOPSCopyPowerSourcesInfo(来自IOPowerSources.h)返回一个NSDictionary,其中包含更多信息,如电池运行状况。