views:

226

answers:

1

Hi all, I am developing an application in cocoa .My application shows a pop up sheet initially .Now i need to know which event is fired when we try to exit the application by right clicking and selecting "exit" on the icon in dock,because i cant exit the appication because of the popup sheet ..looking for a solution

+1  A: 

Your app is sent a quit Apple Event when the Quit item is selected in the Dock menu. If you want to intercept this you will need to install a custom Apple Event Handler for this event. Note that it's normal for sheets to prevent application termination until the sheet is dismissed, so if you change this behavior your app will work differently to other applications.

Here is a simple example of how to override the default handler for quit Apple Events in your application delegate:

- (void)applicationDidFinishLaunching:(NSNotification*)notification
{
    //install the custom quit event handler
    NSAppleEventManager* appleEventManager = [NSAppleEventManager sharedAppleEventManager];
    [appleEventManager setEventHandler:self andSelector:@selector(handleQuitEvent:withReplyEvent:) forEventClass:kCoreEventClass andEventID:kAEQuitApplication];
}

//handler for the quit apple event
- (void)handleQuitEvent:(NSAppleEventDescriptor*)event withReplyEvent:(NSAppleEventDescriptor*)replyEvent
{
    [self terminate:self];
}
Rob Keniger
Thank you so much......
Sreelal