2009-11-20 73 views
2

我正在开发一个可可应用程序。我的应用程序最初显示了一个弹出窗口。现在我需要知道哪个事件被激发,当我们尝试退出应用程序时,右键单击并选择“退出”在码头上,因为我不能退出应用程序,因为弹出式页面..正在寻找解决方案应用程序退出事件

回答

6

当您在Dock菜单中选择退出项目时,您的应用程序会发送一个quit Apple事件。如果你想拦截这个,你需要为这个事件安装一个自定义的Apple Event Handler。请注意,在表单被解除之前阻止应用程序终止是正常的,因此如果更改此行为,您的应用程序将以与其他应用程序不同的方式工作。

下面是如何覆盖quit苹果事件的默认处理程序在你的应用程序委托一个简单的例子:

- (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

太感谢你了...... – MobX 2009-11-20 07:10:09