views:

216

answers:

1

What I wanted to do is take a log on battery percentage. I know the equivalent in linux is sysctl(hw.acpi.battery.life). However when I went through the man of sysctl in mac os x I did not find the equivalent code to find it. Can some one point out how to do this using objective c. I can call sysctlbyname but that doesn't have this as input in its struct. Kindly help me please

+8  A: 

Try using IOKit and the IOPowerSources functions. You can use IOPSCopyPowerSourcesInfo() to get a blob, and IOPSCopyPowerSourcesList() to then extract a CFArray out of that, listing the power sources. Finally you can use the IOPSGetPowerSourceDescription() to grab the dictionary.

If you can use the command line, you can use the pmset command

Like so:

$ pmset -g
Dominic Bou-Samra
+1 on IOPowerSources
Stephen Canon