Application exit event

后端 未结 1 1729
时光说笑
时光说笑 2021-01-23 05:53

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 cli

1条回答
  •  不知归路
    2021-01-23 06:28

    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];
    }
    

    0 讨论(0)
提交回复
热议问题