Woj*_*ski 4 battery uidevice ios
我想知道是否可以在 iOS 中接收有关电池的信息,例如:容量 (mA)、电压 (V)、循环计数?
我知道 UIDevice 类,但电池电量不是我想要的。
试试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;
}
Run Code Online (Sandbox Code Playgroud)
我对此可能是错的,但使用公共 API 这是不可能的。根据UIDevice文档,您最多能做的就是获取电池电量、状态并启用电池监控。
2019 年 2 月 15 日更新:看起来 iOS UIDeviceAPI 现在允许开发人员访问设备的电池电量。呼!目前它公开了 4 个不同的 API。从表面上看,这些并不是“私有的”,换句话说,开发者可以安全地使用它们,而 Apple 不会阻止您的应用程序进入 AppStore。
获取设备电池状态
var batteryLevel: Float(设备的电池电量)。var isBatteryMonitoringEnabled: Bool(一个布尔值,指示是否启用电池监控(true)或未启用(false))。var batteryState: UIDevice.BatteryState(设备的电池状态)。enum UIDevice.BatteryState(设备的电池电量状态)。