How to disable the screen saver/display sleep on M

2019-04-07 06:04发布

问题:

Is there a way to disable the screen saver and the display sleep with cocoa?

回答1:

The use of UpdateSystemActivity(OverallAct) has been deprecated in OSX 10.8.

The recommended approach is now to block it with the following call:

IOPMAssertionCreateWithName(kIOPMAssertionTypePreventUserIdleDisplaySleep,
                            kIOPMAssertionLevelOn, reasonForActivity, &assertionID);

See this Apple Q&A for further details.



回答2:

i've just solved it and forgot to post it as an answer. Calling UpdateSystemActivity(OverallAct) every 30 seconds works.