简体   繁体   English

如何从连接的iOS设备获取电池充电周期?

[英]How Do I get Battery Charge Cycles from a connected iOS device?

I'm using MobileDevice.framework in an OS X application and I've been able to get how charged the battery of an iOS device connected over USB is using the AMDeviceCopyValue(device, domain, key) function with the arguments "com.apple.mobile.battery" for the domain and "BatteryCurrentCapacity" for the key . 我在OS X应用程序中使用MobileDevice.framework ,我已经能够通过USB连接的iOS设备的电池使用AMDeviceCopyValue(device, domain, key)函数和参数"com.apple.mobile.battery"用于domain"BatteryCurrentCapacity"用于key

I want to also get the number of Charge Cycles on the battery. 我还想获得电池充电周期数。 I believe it's possible because iBackupBot is able to fetch that data. 我相信这是可能的,因为iBackupBot能够获取该数据。 Does anyone know how it does this? 有谁知道这是怎么回事? I downloaded the free copy of the program and tested it on an iPhone 3GS , iPhone 4S , and an iPhone 5 . 我下载了该程序的免费副本,并在iPhone 3GSiPhone 4SiPhone 5 It was able to grab the data for all three devices. 它能够获取所有三个设备的数据。

I have run iBackupBot through LLDB and logged its every usage of AMDeviceCopyValue() . 我已通过LLDB运行iBackupBot并记录其AMDeviceCopyValue()每次使用情况。 In doing so, I determined that it isn't getting the Charge Cycles count from that. 在这样做的过程中,我确定它没有从中获得Charge Cycles计数。

You can grab CycleCount and a bunch of other information using an ioreg (IORegistry) dump of the device. 您可以使用设备的ioreg (IORegistry)转储获取CycleCount和一堆其他信息。 For example, see here for an IORegistry dump of the iPhone 5S. 例如,请参阅此处了解iPhone 5S的IORegistry转储。 Note this section: 请注意本节:

 +-o AppleD2045PMUPowerSource  <class AppleD2045PMUPowerSource, busy 0, retain count 10>
    | |   |   |   |   {
    | |   |   |   |     "battery-data" = {
                            .....
                            "CycleCount" = 1
        | |   |   |   |     "ChargerConfiguration" = 960
        | |   |   |   |     "DesignCapacity" = 1550
        | |   |   |   |     "BatteryData" = {"BatterySerialNumber"="C0133237ALXFHCWBP","ChemID"=4484,"Flags"=256,"QmaxCell0"=1619,"Voltage"=4051,"CycleCount"=1,"StateOfCharge"=72,"DesignCapacity"=1550,"FullAvailableCapacity"=1573,"MaxCapacity"=1517,"MfgData"=<4330313333323337414c58464843574250000000000000010000010000000100>,"ManufactureDate"="1332"}
        | |   |   |   |     "AtCriticalLevel" = No

The private IOKit.framework on iOS has an API for accessing all of this information (you can look at the dump to figure out the property names, etc. in order to be able to access it programatically). iOS上的私有IOKit.framework有一个用于访问所有这些信息的API(您可以查看转储以找出属性名称等,以便能够以编程方式访问它)。 Erica Sadun has some open source code that uses private IOKit functions to access some device hardware information (without a jailbreak, IIRC) so maybe that will be helpful. Erica Sadun有一些开源代码 ,它使用私有IOKit函数来访问一些设备硬件信息(没有越狱,IIRC),所以这可能会有所帮助。

As for grabbing this info from a Mac, no idea. 至于从Mac上抓取这些信息,不知道。 If you have an on device app that can pull the information from the IORegistry and send it to the Mac over USB that would work. 如果你有一个设备上的应用程序,可以从IORegistry提取信息,并通过USB将其发送到Mac上。 If you wanted to do it without having any additional software installed on the device, you would have to figure out a way to remotely get an ioreg dump. 如果您想在没有在设备上安装任何其他软件的情况下执行此操作,则必须找到远程获取ioreg转储的方法。

Hope this gets you somewhere! 希望这能让你到达某个地方!

I guess You are talking about to get devices battery status, After enabled batteryMonitoringEnabled of UIDevice object you can get current state and level of the battery , 我猜你正在谈论获得设备电池状态,启用了UIDevice对象的batteryMonitoringEnabled ,你可以获得电池的当前状态和电平,

Like, 喜欢,

UIDevice *device = [UIDevice currentDevice];
device.batteryMonitoringEnabled = YES;
NSLog(@"State: %i Charge: %f", device.batteryState, device.batteryLevel);

There is different UIDeviceBatteryState of device from you can get 你可以得到不同的UIDeviceBatteryState设备

  • UIDeviceBatteryStateUnplugged, UIDeviceBatteryStateUnplugged,
  • UIDeviceBatteryStateCharging, UIDeviceBatteryStateCharging,
  • UIDeviceBatteryStateFull, UIDeviceBatteryStateFull,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM