macOS中的电池状态API? [英] Battery status API in macOS?
问题描述
如何从自己的应用程序读取MacBookPro上电池的状态?
How can I read the status of the battery on my MacBookPro from my own application?
Google到目前为止仅公开了用于设备驱动程序以处理电源事件的API-与用户土地进程访问此信息无关.
Googling has so far only revealed APIs for device drivers to handle power events - there's nothing about user-land processes accessing this information.
谢谢.
推荐答案
您将为此使用IOKit,特别是 IOPSKeys.h 字典的内容).
You'll want to use IOKit for this, specifically 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. Then use IOPSGetPowerSourceDescription()
to pull out a dictionary (see IOPSKeys.h for the contents of the dictionary).
这篇关于macOS中的电池状态API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!