首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在iOS中获取电池温度的详细信息?

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

Stack Overflow用户
提问于 2016-08-08 07:14:49
回答 3查看 7.3K关注 0票数 0

我得到电池状态和其他。

代码语言:javascript
复制
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;
    }
}

现在我试着得到温度的细节,它有可能从设备获得电池温度。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2016-08-08 07:46:08

兄弟,我对你的问题作了回答,这表明你可以得到,一般来说,它显示了以下状态

代码语言:javascript
复制
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

以下还显示了电池的运行结果

代码语言:javascript
复制
{
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类中,我放置断点并检查that.It,调用它并带来有关电池的所有信息。

代码语言:javascript
复制
- (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];
}

打印的报表如下

代码语言:javascript
复制
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;
}

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

代码语言:javascript
复制
The battery Temperature is - 3120
票数 0
EN

Stack Overflow用户

发布于 2016-08-08 07:23:32

是不可能的,也没有公共API可以找到。,但是我在这里找到了一些答案,也许它对你有帮助,见过一次。但是一些私有API,您可以获得这些细节。

如果您将应用程序部署在Apple上,则无法使用样本应用程序,但在部署到TestFlight时,它可能很有用

票数 1
EN

Stack Overflow用户

发布于 2022-11-17 09:40:07

如果您不需要温度编号,那么使用ThermalState api是有用的。

https://developer.apple.com/documentation/foundation/nsprocessinfothermalstate?language=objc

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38823260

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档