Prevent Sleep in OSX 10.14 App

I've a sandboxed app that I'd like to prevent screen sleep. I've seen this Q&A and used it's example code as well as thisStackOverflow question.


Neither seem to work. I'm building for OSX 10.13+ in Swift, but using a bridging-header for the code.


Does anyone know if there is newer methods or if the support for this has been dropped in later OSX'

Which Mac are you running on ? MacBook or iMac ?


If MacBook, did you keep the charger plugged. If not, I would try.

Thanks, I’ve tried it on a MacBook Pro and a Mac Mini - same results.

Could you post the code so that we can try ?

Thanks for taking the time. It’s the same code as in the Q&A that I linked to in the original post.

Which of the 2 solutions ?

- Cocoa (Listing 1)

or

- I/O Kit (Listing 3, Listing 4)

I've used both Listing 2 and Listings 3&4. Most links I've found around the web seem to use Listing 2 which is certainly the 'cleaner' of the two.

Prevent Sleep in OSX 10.14 App
 
 
Q