2013-03-13 33 views
3

我註冊使用NSAppleEventManager蘋果事件處理程序:回覆的蘋果事件在可可

[[NSAppleEventManager sharedAppleEventManager] 
    setEventHandler:self andSelector:@selector(handleGetURLEvent:withReplyEvent:) 
     forEventClass:kInternetEventClass andEventID:kAEGetURL]; 

我的處理方法,當然,對事件進行接收和回覆事件:

- (void) handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent { 
    //Open this URL; reply if we can't 
} 

因此,如果我需要回復一個錯誤,表明我以某種方式打開此URL失敗,那麼我應該如何使用replyEvent來做到這一點?

回答

5

我已經翻譯了從蘋果公司的遺留文檔中描述的舊的C程序API下面的「蘋果事件編程指南」可可:

if ([replyEvent descriptorType] != typeNull) 
{ 
    [replyEvent setParamDescriptor:[NSAppleEventDescriptor descriptorWithInt32:someStatusCode] forKeyword:keyErrorNumber]; 
    [replyEvent setParamDescriptor:[NSAppleEventDescriptor descriptorWithString:someErrorString] forKeyword:keyErrorString]; 
} 

See "Returning Error Information" in the "Apple Events Programming Guide"(在舊庫)。

+0

但如何發送此回覆? – jimwan 2017-02-21 05:45:48

+0

@ jimwan:可可自動發回。它向你提供了一個物件供你填寫細節。 (實際上,Cocoa只是作爲一個介於兩者之間的底層Apple底層事件API爲Cocoa提供了回覆事件對象並自動發回。) – 2017-02-21 23:06:08