申请退出事件

Mob*_*obX 2 macos cocoa objective-c appleevents

我正在开发一个可可的应用程序.我的应用程序最初显示一个弹出工作表.现在我需要知道当我们尝试通过右键单击并在dock中的图标上选择"exit"退出应用程序时触发了哪个事件,因为我无法退出应用程序,因为弹出表..寻找解决方案

Rob*_*ger 6

quit在Dock菜单中选择退出项目后,您的应用程序将发送Apple事件.如果要拦截此事件,则需要为此事件安装自定义Apple事件处理程序.请注意,在工作表被解除之前,工作表通常会阻止应用程序终止,因此如果您更改此行为,您的应用程序将与其他应用程序的工作方式不同.

以下是如何quit在应用程序委托中覆盖Apple Events 的默认处理程序的简单示例:

- (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];
}
Run Code Online (Sandbox Code Playgroud)