在主消息循环中标识AppleEvents

时间:2015-05-21 14:41:50

标签: objective-c events message-queue appleevents

我有一个主消息循环。我正在寻找一种方法来检查该活动是否是AppleEvent,以及它的活动类是否属于MyClass'然后做点什么。 我查看了NSEvent的参考资料,但却没有找到我需要的东西。 请有人建议采用一种方法吗?

while (!shutdown_now_) 
    {
        NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
        NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask
                                            untilDate:[NSDate distantFuture]
                                               inMode:NSDefaultRunLoopMode
                                              dequeue:YES];

        //if event is AppleEvent AND event class is <MyEventClass> then do something

        if (event) [NSApp sendEvent:event];
        [pool drain];
}  

1 个答案:

答案 0 :(得分:0)

你不能在你的循环中通过NSEvent获得Apple活动。

因为NSEvent没有覆盖它。

Documentation

  

Cocoa应用程序中的几乎所有事件都由对象表示   NSEvent类。 (例外情况包括Apple活动,通知,   和类似项目。)每个NSEvent对象更狭义地代表一个   特定类型的事件,每个事件都有自己的处理要求。   以下部分描述了NSEvent的特征   对象和可能的事件类型

您可以在NSApplication documentation

中找到更多信息

相反,您可以使用NSAppleEventManager类通过以下method

注册您自己的Apple事件处理程序
- (void)setEventHandler:(id)handler
            andSelector:(SEL)handleEventSelector
          forEventClass:(AEEventClass)eventClass
             andEventID:(AEEventID)eventID