macOS 中的电池状态 API? [英] Battery status API in macOS?

查看:32
本文介绍了macOS 中的电池状态 API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从我自己的应用程序中读取 MacBookPro 上的电池状态?

How can I read the status of the battery on my MacBookPro from my own application?

到目前为止,谷歌搜索只揭示了设备驱动程序处理电源事件的 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,特别是 IOPowerSources 函数.您可以使用 IOPSCopyPowerSourcesInfo() 获取一个 blob,然后使用 IOPSCopyPowerSourcesList() 从中提取一个 CFArray,列出电源.然后使用 IOPSGetPowerSourceDescription() 拉出一个字典(见 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆