2015-05-21 58 views
0

我有一個主消息循環。我正在尋找一種方法來檢查事件是否是AppleEvent,如果事件類是'MyClass',那麼做一些事情。 我看了NSEvent參考,並失去了沒有找到我所需要的。 請有人建議一種方法?識別主消息循環中的AppleEvents

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]; 
} 

回答

0

在這樣的循環中,您無法通過NSEvent獲得Apple事件。因爲NSEvent只是不覆蓋它。

Documentation

幾乎在Cocoa應用程序中的所有事件都通過 的NSEvent類對象表示。 (例外情況包括Apple事件,通知, 及類似項目)每個NSEvent對象更狹義地表示一個特定類型的事件,每個事件都有自己的處理要求。 以下部分描述了一個NSEvent 對象的特點和可能​​的事件類型

你可以找到NSApplicationdocumentation


一些更多的信息,相反,你可以使用NSAppleEventManager類註冊自己Apple事件處理程序method

- (void)setEventHandler:(id)handler 
      andSelector:(SEL)handleEventSelector 
      forEventClass:(AEEventClass)eventClass 
      andEventID:(AEEventID)eventID 
+0

AppleEvent就像從消息隊列中派發的其他事件一樣。如果事件是Apple事件,它將被髮送到正在查看調度表並調用註冊處理程序的AppleEvent Manager。我知道如何註冊處理程序,它適用於我。 – Sanich

+0

Apple事件是NSEvent涵蓋的例外。檢查更新的答案 – deimus

+0

我已經調試了循環。 AppleEvents正從nextEventMatchingMask重定向到AppleEvent Manager – Sanich