如何在 iOS 中获取电池温度详细信息?

Posted

技术标签:

【中文标题】如何在 iOS 中获取电池温度详细信息?【英文标题】:How to get the battery temperature details in iOS? 【发布时间】:2016-08-08 07:14:49 【问题描述】:

我正在获取电池状态和其他信息。

UIDevice *myDevice = [UIDevice currentDevice];
[myDevice setBatteryMonitoringEnabled:YES];
float batLeft = [myDevice batteryLevel];
int i=[myDevice batteryState];

int batinfo=(batLeft*100);

NSLog(@"Battry Level is :%d and Battery Status is :%d",batinfo,i);

switch (i)

    case UIDeviceBatteryStateUnplugged:
    

        break;
    
    case UIDeviceBatteryStateCharging:
    

        break;
    
    case UIDeviceBatteryStateFull:
    

        break;
    
    default:
    

        break;
    

现在我正在尝试获取温度详细信息,是否可以从设备获取电池温度。

【问题讨论】:

Obtain Battery temperature in ios programatically的可能重复 【参考方案1】:

这是不可能的,也没有可找到的公共 API。 但我在这里找到了一些答案,可能对你有帮助,see once。但是一些私有 API 你可以得到这个细节。

sample app如果您在 Apple Store 上部署您的应用程序,则无法使用此功能,但在部署到 TestFlight 时会很有用

【讨论】:

【参考方案2】:

大哥,你的问题的答案我看完了,说明你可以得到,一般显示如下状态

Battery design capacity
Battery current raw capacity (in mAh)
Battery cycle count
Current battery temperature
Current battery voltage
Current battery discharge rate (device power consumption), in mA

下面也显示了电池的结果


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;

以上内容来自UIDeviceListener

我使用低于温度的示例代码运行

在 EEPowerInformation.m 类中,我放置断点并检查它。它被调用并带来有关电池的所有信息。

- (void) listenerDataUpdated: (NSNotification *) notification

  latestPowerDictionary = notification.userInfo;
  NSLog(@"The latest Power Dictionary is - %@",latestPowerDictionary);
  NSLog(@"The battery Temperature is - %@",[latestPowerDictionary objectForKey:@"Temperature"]);
  if (self.delegate != nil)
    [self.delegate powerInformationUpdated: self];

打印出来的报表是

The latest Power Dictionary is - 
AdapterDetails =     
    Amperage = 1000;
    Description = "usb host";
    FamilyCode = "-536854528";
    PMUConfiguration = 970;
    Watts = 5;
;
AdapterInfo = 16384;
Amperage = 1000;
AppleChargeRateLimitIndex = 0;
AppleRawBrickIDVoltages =     (
            (
        39,
        420
    )
);
AppleRawCurrentCapacity = 1084;
AppleRawExternalConnected = 1;
AppleRawMaxCapacity = 1221;
AtCriticalLevel = 0;
AtWarnLevel = 0;
BatteryInstalled = 1;
BatteryKey = "0003-default";
BootBBCapacity = 673;
BootCapacityEstimate = 29;
BootVoltage = 3810;
CFBundleIdentifier = "com.apple.driver.AppleARMPlatform";
ChargerConfiguration = 900;
CurrentCapacity = 1222;
CycleCount = 343;
DesignCapacity = 1430;
ExternalChargeCapable = 1;
ExternalConnected = 1;
FullyCharged = 0;
IOClass = AppleARMPMUCharger;
IOFunctionParent5E000000 = <>;
IOGeneralInterest = "IOCommand is not serializable";
IOMatchCategory = IODefaultMatchCategory;
IONameMatch = charger;
IONameMatched = charger;
IOPowerManagement =     
    CapabilityFlags = 32832;
    CurrentPowerState = 2;
    DevicePowerState = 2;
    MaxPowerState = 2;
;
IOProbeScore = 1000;
IOProviderClass = IOService;
InstantAmperage = 198;
IsCharging = 1;
Location = 0;
Manufacturer = A;
MaxCapacity = 1300;
Model = "0003-A";
Temperature = 3120;
TimeRemaining = 67;
UpdateTime = 1470665642;
Voltage = 4188;
"built-in" = 1;

最后打印的电池温度结果是

The battery Temperature is - 3120

【讨论】:

用户感谢您的回答,但它是准确的温度还是假设@user3182143 不是假设兄弟它是 UIDeviceListener 的实际输出 兄弟,我实际上添加了你的代码,它给了我零,因为我在模拟器上运行它,一旦我在设备上验证它,我就放弃了投票,然后我给出了正确的答案 与设备兄弟一起运行 今天不可能 兄弟设备不在这里,明天我会检查大部分我会尝试在今天之前检查它

以上是关于如何在 iOS 中获取电池温度详细信息?的主要内容,如果未能解决你的问题,请参考以下文章

修改黑苹果如何驱动硬件传感器?获取CPU温度详细信息教程

如何以编程方式获取完整的 ios 设备详细信息

如何在 iOS 7 中使用 iBeacons 获取设备详细信息,如 UUID 或设备名称

如何在 iOS 中获取大量电池信息?

python如何获取服务器硬件状态信息,包括CPU温度、硬盘温度、主板电池电压、主机电源电压、CPU风扇转速?

手机电池材质、温度、电压等信息如何查看?