【问题标题】:Replying to an Apple Event in Cocoa在 Cocoa 中回复 Apple 事件
【发布时间】:2013-03-13 10:29:53
【问题描述】:

我正在使用 NSAppleEventManager 注册一个 Apple 事件处理程序:

[[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 来做到这一点?

【问题讨论】:

    标签: macos cocoa appleevents nsappleeventmanager


    【解决方案1】:

    我已将 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];
    }
    

    See "Returning Error Information" in the "Apple Events Programming Guide"(在旧版库中)。

    【讨论】:

    • 但是如何发回这个回复?
    • @jimwan:Cocoa 会自动将其发回。它给你一个对象,让你填写详细信息。 (实际上,Cocoa 只是充当中间人。底层的 Apple Event API 将回复事件对象提供给 Cocoa 并自动将其发回。)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-15
    • 2016-08-10
    相关资源
    最近更新 更多