我想做的是记录电池百分比。我知道linux中的等效项是sysctl(hw.acpi.battery.life)。然而,当我在 mac os x 中查看 sysctl 的 man 时,我没有找到等效的代码来找到它。有人可以指出如何使用 Objective c 来做到这一点吗?我可以调用 sysctlbyname 但它的结构中没有此作为输入。请帮助我
尝试使用IOKit http://developer.apple.com/mac/library/documentation/DeviceDrivers/Conceptual/IOKitFundamentals/Families_Ref/Families_Ref.html#//apple_ref/doc/uid/TP0000021-BABCCBIJ和IO电源 http://developer.apple.com/mac/library/documentation/Darwin/Reference/IOKit/IOPowerSources_h/index.html功能。您可以使用IOPSCopyPowerSourcesInfo() http://developer.apple.com/mac/library/documentation/Darwin/Reference/IOKit/IOPowerSources_h/index.html#//apple_ref/c/func/IOPSCopyPowerSourcesInfo得到一个斑点,并且IOPSCopyPowerSourcesList() http://developer.apple.com/mac/library/documentation/Darwin/Reference/IOKit/IOPowerSources_h/index.html#//apple_ref/c/func/IOPSCopyPowerSourcesList然后从中提取一个 CFArray,列出电源。最后你可以使用IOPSGetPowerSourceDescription() http://developer.apple.com/mac/library/documentation/Darwin/Reference/IOKit/IOPowerSources_h/index.html#//apple_ref/c/func/IOPSCopyPowerSourcesInfo去抢字典。
如果您可以使用命令行,则可以使用pmset http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man1/pmset.1.html command
Like so:
$ pmset -g
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)