Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
610 views
in Technique[技术] by (71.8m points)

objective c - How to wake from sleep programmatically if lid closed?

I want to wake system from sleep programmatically, is there any way to do this?

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:

As per the suggestion I tried with IOPMSchedulePowerEvent

Code I have used:

NSCalendarDate  *timeIntervalSinceNow = [NSCalendarDate dateWithTimeIntervalSinceNow:40];
IOReturn result = IOPMSchedulePowerEvent ((CFDateRef)timeIntervalSinceNow, NULL, CFSTR(kIOPMAutoWake)); 

Result:

It fails in MacBook if lid closed

Am I doing some thing wrong or Any solution?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

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.

Edit:

Normal sleep is different from clamshell closed sleep. To affect the latter you must write a kernel extension like Insomnia.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...