When a user tries to log out or disconnect, the system will ask all applications to log out. If any statements refuse to terminate, the action will be canceled. Since you want to undo these actions, you probably also want to prevent the application from closing normally. As part of the completion sequence, the application requests permission from its delegate. Therefore, to cancel exits and shutdowns, and also to prevent the user from exiting the application normally, you can use the application delegate to refuse the action.
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender if([self shouldPreventTermination]) return NSTerminateCancel; return NSTerminateNow; }
source share