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

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

问题描述

如何从自己的应用程序读取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屋!

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