我想为Mac(Mavericks)制作一个不处理命令退出选项的应用程序。
我找到了以下解决方案,但它必须已过时,因为我收到错误:
CFMachPortRef eventTap = CGEventTapCreate(kCGHIDEventTap,
kCGHeadInsertEventTap,
kCGEventTapOptionDefault,
CGEventMaskBit(kCGEventKeyDown),
&KeyDownCallback,
NULL);
CFRunLoopSourceRef runLoopSource = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, eventTap, 0);
CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopCommonModes);
CFRelease(runLoopSource);
CGEventTapEnable(eventTap, true);
还有其他方法吗?感谢。
答案 0 :(得分:4)
让应用程序委托实现applicationShouldTerminate:
方法:
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
{
// work out whether to actually quit or not
BOOL shouldQuit = /* insert logic here */;
if (shouldQuit)
return NSTerminateNow;
else
return NSTerminateCancel;
}