1
Mac OSのアプリケーションが終了すると、「[はい] [いいえ]」を終了してもよろしいですか?ドックに私のアプリを右クリックし、「終了」を選択するときが来るNSAppleEventManagerですべての終了イベントをキャッチ
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
// Install a 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 {
// Insert YES/NO-dialog here
// if(blahahaha..
//[NSApp terminate:self];
}
をしかし、それだけで終了キャッチ:
私はこれを試してみました。 Cmd-Qを押すか、アプリケーションメニューから終了を選択した場合、ハンドラは呼び出されません。
ありがとう、素晴らしい作品:) – user872661