I'm looking for a way to authenticate a macOS app that would allow the app to wake the user's Mac from sleep.
I'm aware that I can schedule a power event to wake the computer using similar code to what is provided here.
When I run the IOPMSchedulePowerEvent code, the value of "result" in the code below is (IOReturn) result = -536870207.
IOReturn result = IOPMSchedulePowerEvent(CFBridgingRetain(someCFDate), NULL, CFSTR(kIOPMAutoWake));
After doing some digging and finding someone with a similar issue on this forum post, I'm pretty confident that the root of my problem lies in needing to authenticate the app to allow it to wake the user's Mac from sleep. I've found some of the apple documentation for local authentication here, but it still doesn't seem to fully address my issue.
So, in short, how can I provide the app the authentication it needs to wake a Mac from sleep?
Edit: I've been looking into the issue some more, and I think I've been making good progress.
For starters, the reason I was getting the kIOReturnNotPrivileged
was because you have to run the app as root in Xcode. This can be accomplished by editing the debug scheme via Product > Scheme > Edit Scheme and by changing the "Debug Process as" option to "Root".
Setting the app to run as root, I am able to properly schedule the power events to put my machine to sleep and wake it up at prescribed times.
There seems to be some other issues that crop up in Xcode 8.3 if you have your app sandboxed and running as root. I'll create another post to ask this question.