2009-11-20 10 views
2

나는 코코아에서 응용 프로그램을 개발 중입니다. 내 응용 프로그램은 처음에 팝업 시트를 보여줍니다. 이제 우리는 아이콘에서 "종료"를 선택하여 응용 프로그램을 종료하려고 할 때 어떤 이벤트가 시작되는지 알아야합니다. 도크에서 팝업 시트 때문에 appication을 종료 할 수 없으므로 ...응용 프로그램 종료 이벤트

답변

6

Dock 메뉴에서 종료 항목을 선택하면 앱에 quit Apple 이벤트가 전송됩니다. 이것을 가로 채고 싶다면이 이벤트를 위해 커스텀 애플 이벤트 핸들러를 설치해야합니다. 시트가 닫힐 때까지 시트가 응용 프로그램 종료를 막는 것은 정상이므로이 동작을 변경하면 응용 프로그램이 다른 응용 프로그램과 다르게 작동합니다. ......

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

너무 감사 :

여기에 응용 프로그램 위임에 quit 애플 이벤트에 대한 기본 핸들러를 오버라이드 (override)하는 방법에 대한 간단한 예입니다 – MobX

관련 문제