如何获得Mac OS X的MacBook笔记本的电池续航时间编程? [英] How to get the battery life of mac os x macbooks programatically?
问题描述
我想要做的就是采取电池百分比日志。我知道在Linux中是等价的sysctl(hw.acpi.battery.life)。然而,当我经历的sysctl在Mac OS X中的人走到我没有找到,相当于code找到它。可有一个人点了怎么做到这一点使用Objective C的。我可以调用sysctlbyname但不具有本作中,其结构的输入。请帮助我,请
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
推荐答案
尝试使用<一个href=\"http://developer.apple.com/mac/library/documentation/DeviceDrivers/Conceptual/IOKitFundamentals/Families%5FRef/Families%5FRef.html#//apple%5Fref/doc/uid/TP0000021-BABCCBIJ\">IOKit和<一个href=\"http://developer.apple.com/mac/library/documentation/Darwin/Reference/IOKit/IOPowerSources%5Fh/index.html\">IOPowerSources功能。您可以使用<一个href=\"http://developer.apple.com/mac/library/documentation/Darwin/Reference/IOKit/IOPowerSources%5Fh/index.html#//apple%5Fref/c/func/IOPSCopyPowerSourcesInfo\">IOPSCopyPowerSourcesInfo()获得BLOB和<一个href=\"http://developer.apple.com/mac/library/documentation/Darwin/Reference/IOKit/IOPowerSources%5Fh/index.html#//apple%5Fref/c/func/IOPSCopyPowerSourcesList\">IOPSCopyPowerSourcesList()然后,以提取出CFArray那,列出了电源。最后,你可以使用IOPSGetPowerSourceDescription()抢字典。
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.
如果您可以使用命令行,您可以使用 pmset命令
If you can use the command line, you can use the pmset command
像这样:
$ pmset -g
这篇关于如何获得Mac OS X的MacBook笔记本的电池续航时间编程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!