6

I'm building a mac app that I want to distribute in the mac app store. I need this app to have a lock screen feature.

I have 2 different approaches working, the problem is, as soon as I enable sandboxing for the app (which is required for the mac app store), neither of those approaches will work.

Do you know which entitlement I need to request? Or do you know of a third approach that will work with sandboxing?

Thanks

Approach 1, using CGSession (swift):

var arguments = ["-suspend"]
var task = NSTask()
task.arguments = arguments
task.launchPath = "/System/Library/CoreServices/Menu Extras/User.menu/Contents/Resources/CGSession"
task.launch()

Approach 2, using IORequestIdle (swift):

var r = IORegistryEntryFromPath(kIOMasterPortDefault, "IOService:/IOResources/IODisplayWrangler") 
if (r > 0) {
  IORegistryEntrySetCFProperty(r, "IORequestIdle", kCFBooleanTrue)
  IOObjectRelease(r)
}
jscs
  • 63,694
  • 13
  • 151
  • 195
saintmac
  • 590
  • 4
  • 15
  • I'm happy with an Objective-C solution by the way – saintmac Nov 07 '14 at 10:48
  • What is the need for lock screen? Privacy? Data protection? Why lock the whole Mac and not only your application? To lock the whole mac ask the user to activate System Preferences > Security > "Require password... after sleep or screen saver" and set an active corner to enter sleep of screen / screensaver. I doubt that this can be done programmatically as it involves admin rights. – mahal tertin Dec 19 '14 at 13:44
  • Because the goal is to lock the mac. Not the app. The goal is to offer a "lock button", not a tutorial on how to lock the mac (which we are already doing in the meantime) It can be done programmatically because we've already done it with the app out of Sandbox mode. The question is about how to do it in sandbox mode (to distribute the app) – saintmac Dec 19 '14 at 14:19
  • FYI the Keychain Access app can put a "lock screen" item in the menu bar at all times if you enable the corresponding option in its preferences. – nobody Dec 19 '14 at 21:44
  • Yes I know, thanks, that is what our tutorial is saying for now – saintmac Dec 20 '14 at 12:30

1 Answers1

0

Sorry to say it can't be done. the purpose of sandboxing is to prevent an app can take the whole computer.

You might try to get a temporary exception thru the channels documented in the sandboxing guide.

mahal tertin
  • 3,239
  • 24
  • 41