问题
I'm in the process of writing a Mac (10.6 / 10.7) application that authenticates users against an Active Directory domain before allowing them access to the computer (I'm told I can't allow users to log on via traditional log on services). I have the authentication code in place, and am now trying to make this login window fullscreen and unable to close.
Apple's Kiosk Mode API (documentation here) seems like a great fit for this, and I've used it to bring the window fullscreen, disable the dock / menu bar / force quit, etc., all of which works fine. The problem I'm having is that I can't seem to prevent users from simply CMD+Q'ing out of the application.
There's no point in a kiosk mode application with limitations when a user can just quit out of it, so I'm assuming I'm missing something. Below is an example of what I'm doing:
NSApplicationPresentationOptions options =
NSApplicationPresentationHideMenuBar|NSApplicationPresentationHideDock|
NSApplicationPresentationDisableHideApplication|
NSApplicationPresentationDisableProcessSwitching|
NSApplicationPresentationDisableAppleMenu| NSApplicationPresentationDisableForceQuit;
[NSApp setPresentationOptions:options];
[[_window contentView] enterFullScreenMode:[NSScreen mainScreen] withOptions:nil];
Result: Full screen window, no menu bar, no dock, can't force quit and can't CMD+Tab away from the screen. CMD+Q still quits the application.
回答1:
I'm guessing he found the same solution that I did, but since it isn't actually answered here I thought I'd detail it.
What you need to do is to implement the following NSApplicationDelegate method:
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
And then return NSTerminateCancel here when your app is in Kiosk mode.
来源:https://stackoverflow.com/questions/11434497/mac-kiosk-mode-api-prevent-users-from-quitting