可可获取电源适配器状态

发布于 2024-10-09 16:46:51 字数 332 浏览 2 评论 0原文

我目前正在开发一个备份应用程序,最近收到了很多要求添加功能的请求,其中最重要的一个是添加一个复选框,例如“使用电池电源时备份”,就像时间机器一样。

那么,有没有办法获取电源适配器的状态(已插入和已插入)?我想如果有人有一台台式 Mac,比如 iMac 等,我可能会一直插着电源。因此,我需要检测计算机是否是便携式计算机的方法。

我认为 IOKit 是一个值得一看的库,但我在文档中找不到任何内容,无论如何,该框架上几乎不存在这些内容。那么,由于它是一个较旧的 Carbon 框架,有没有办法注册一个回调,当电源状态发生变化时调用该回调?这样我就可以正确实现这个复选框的功能。

我希望能帮助澄清这个主题。

I'm currently working on a Backup Application, and I have received a lot of requests for features to be added recently, and the top one of them is adding a checkbox like "Back Up when on Battery Power" like Time Machine has.

So, is there a way I can get the status of the Power Adapter (plugged in and plugged in)? I assume that if one had a Desktop Mac, like iMac, etc, I would probably just get Plugged In all the time. Therefore, I need means of detecting if the computer is a portable or not.

I assume IOKit would be a library to look at, but I simply could not find anything in the docs, that are barely existent anyways on that Framework. Then, since it is an older Carbon Framework, is there a way to register a callback that gets called when that power state changes? That way I can properly implement this checkbox's functionality.

I'd appreciate help in clarifying this subject.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

葬シ愛 2024-10-16 16:46:51

IOPowerSources.h 有您需要的功能。从 IOPSNotificationCreateRunLoopSource() 开始创建运行循环源,并在回调中询问电源信息,从 IOPSCopyPowerSourcesInfo() 开始一直向下。可能有更好的示例,但此文件 似乎合理地演示了它是如何完成的;足以让你开始。

IOPowerSources.h has the functions you need. Start with IOPSNotificationCreateRunLoopSource() to create a run loop source and in your callback interrogate the power source info starting with IOPSCopyPowerSourcesInfo() and working your way down. There may be better examples, but this file appears to be a reasonable demonstration of how it's done; enough to get you started.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文