Pet*_*sey 5 macos cocoa appleevents nsappleeventmanager
我正在使用NSAppleEventManager注册Apple事件处理程序:
[[NSAppleEventManager sharedAppleEventManager]
setEventHandler:self andSelector:@selector(handleGetURLEvent:withReplyEvent:)
forEventClass:kInternetEventClass andEventID:kAEGetURL];
Run Code Online (Sandbox Code Playgroud)
当然,我的处理程序方法将接收事件和回复事件:
- (void) handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent {
//Open this URL; reply if we can't
}
Run Code Online (Sandbox Code Playgroud)
所以,如果我需要回复一个错误,表明我以某种方式打开了这个URL,我应该怎么用replyEvent呢?
我已将以下内容从Apple的旧文档"Apple Events Programming Guide"中描述的旧式C过程API转换为Cocoa:
if ([replyEvent descriptorType] != typeNull)
{
[replyEvent setParamDescriptor:[NSAppleEventDescriptor descriptorWithInt32:someStatusCode] forKeyword:keyErrorNumber];
[replyEvent setParamDescriptor:[NSAppleEventDescriptor descriptorWithString:someErrorString] forKeyword:keyErrorString];
}
Run Code Online (Sandbox Code Playgroud)
请参阅"Apple Events编程指南"(旧版库中)中的"返回错误信息".
| 归档时间: |
|
| 查看次数: |
672 次 |
| 最近记录: |