可可获取电源适配器状态
我目前正在开发一个备份应用程序,最近收到了很多要求添加功能的请求,其中最重要的一个是添加一个复选框,例如“使用电池电源时备份”,就像时间机器一样。
那么,有没有办法获取电源适配器的状态(已插入和已插入)?我想如果有人有一台台式 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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 withIOPSCopyPowerSourcesInfo()
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.