A while ago I wrote a program called iox that is similar to ioreg, except it makes it easier for me to translate back to IOKit calls. When I run that on my laptop, I see the following with a battery level.
AppleSmartBattery - IOService:/AppleACPIPlatformExpert/SMB0/AppleECSMBusController/AppleSmartBatteryManager/AppleSmartBattery
CurrentCapacity = 11678
FullyCharged = YES
DesignCapacity = 13000
MaxCapacity = 11910
...
In code, that is
IOServiceNameMatching( "AppleSmartBattery" );
I have no idea if the name would be the same on iOS, but I would try either finding a program like ioreg that you can run on the iPhone, or writing something simple to log the equivalent.
ioreg is part of IOKitTools and it should just compile on iPhone.
Edit:
CFMutableDictionaryRef matching , properties = NULL;
io_registry_entry_t entry = 0;
matching = IOServiceMatching( "IOPMPowerSource" );
//matching = IOServiceNameMatching( "AppleSmartBattery" );
entry = IOServiceGetMatchingService( kIOMasterPortDefault , matching );
IORegistryEntryCreateCFProperties( entry , &properties , NULL , 0 );
NSLog( @"%@" , properties );
CFRelease( properties );
IOObjectRelease( entry );
Add some safety checks. Once you figure out the specific properties you want, you can get them directly instead of using IORegistryEntryCreateCFProperties to get them all at once.
IOKit represents everything as a big tree. IOPMPowerSource may not directly have the attributes you want, in which case you would need to iterate through the children. Using something like ioreg can tell you what you are looking for before you start coding.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…