2013-03-13 50 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