5

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.

mgwiggles
  • 141
  • 5
  • 1
    Indeed, the return value you're getting is `kIOReturnNotPrivileged`. – jtbandes May 29 '17 at 05:07
  • Is your app sandboxed? Have you tried running this from a privileged helper? https://developer.apple.com/library/content/documentation/Security/Conceptual/SecureCodingGuide/Articles/AccessControl.html Note that the LocalAuthentication API you linked to is more about Touch ID than anything else. – jtbandes May 29 '17 at 05:15
  • Hi @jtbandes. Yes, my app is sandboxed. I took a look at the documentation you attached. It looks like a privileged helper would probably get me what I needed. However, it appears that the use of a privileged helper prohibits submitting the app to the App Store. I'm assuming there's not many other ways to allow the app to wake the computer from sleep, so is it better to prohibit sleep in the first place such as what is in the apple documentation [here](https://developer.apple.com/library/content/qa/qa1340/_index.html) – mgwiggles May 29 '17 at 15:28

0 Answers0