问题描述
我想以编程方式将系统从睡眠中唤醒,有什么方法可以做到这一点?
I want to wake system from sleep programmatically, is there any way to do this?
我已阅读以下链接: http://developer.apple.com/mac/library/qa/qa2004 /qa1340.html
I have read following link:http://developer.apple.com/mac/library/qa/qa2004/qa1340.html
这仅是关于获取通知,但不确定是否有任何方法可以将系统从睡眠中唤醒?
this only talk about getting notification , but not sure is there any way to wake system from sleep?
我很感谢这些信息的线索...
I appreciate some thread to the information...
更新:
Update:
根据我尝试使用IOPMSchedulePowerEvent的建议
As per the suggestion I tried with IOPMSchedulePowerEvent
我使用的代码:
NSCalendarDate *timeIntervalSinceNow = [NSCalendarDate dateWithTimeIntervalSinceNow:40];
IOReturn result = IOPMSchedulePowerEvent ((CFDateRef)timeIntervalSinceNow, NULL, CFSTR(kIOPMAutoWake));
结果:
如果MacBook主机盖关闭,它将失败
It fails in MacBook if lid closed
我做错了什么或任何解决方案吗?
Am I doing some thing wrong or Any solution?
推荐答案
您可以通过电源管理器使用IOPMSchedulePowerEvent安排唤醒事件.您也许可以安排立即唤醒. pmset 是命令行电源管理器的包装器.在某些情况下,您还可以使用IOCancelPowerChange防止睡眠.
You can schedule wake up events with IOPMSchedulePowerEvent through the power manager. You may be able to schedule an immediate wake up. pmset is a command line wrapper for the power manager. You can also prevent sleep with IOCancelPowerChange in certain cases.
通过生成鼠标或按键事件,您可以防止睡眠或唤醒.生成事件的一种方法是使用CGPostKeyboardEvent.
You may be able to prevent sleep or wake up by generating a mouse or key event. One way to generate events is with CGPostKeyboardEvent.
正常睡眠不同于翻盖式封闭睡眠.要影响后者,您必须编写 Insomnia 之类的内核扩展.
Normal sleep is different from clamshell closed sleep. To affect the latter you must write a kernel extension like Insomnia.
这篇关于如果机盖关闭,如何以编程方式从睡眠中唤醒?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!