Raphael
Raphael

Reputation: 8192

Preventing the user from logging out or shutting down

I'm developing a Mac OS application and one of the requirements is that this application blocks the user from logging out or shutting down the machine if the user has not finished some tasks within the application. Is it possible to achieve this with Cocoa or Carbon? If so, how could I implement such functionality?

Thank you

Upvotes: 4

Views: 619

Answers (2)

ughoavgfhw
ughoavgfhw

Reputation: 39905

When the user attempts to log out or shut down, the system will ask all applications to quit. If any applications refuse to quit, the action will be canceled. Since you want to cancel these actions, you probably want to prevent the application from quitting normally too. As a part of the termination sequence, the application asks its delegate for permission. Therefore, to cancel log outs and shutdowns, as well as prevent the user from normally quitting your application, you can use the application delegate to deny the action.

- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
    if([self shouldPreventTermination])
        return NSTerminateCancel;
    return NSTerminateNow;
}

Upvotes: 4

Dietrich Epp
Dietrich Epp

Reputation: 213338

This can be achieved with Kiosk mode (documentation). Note that there are often ways around it.

Upvotes: 2

Related Questions