5

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でしょうか?

4

1 に答える 1

8

以下を、Appleのレガシードキュメント「AppleEventsProgrammingGuide」で説明されている古いスタイルのC手続き型APIからCocoaに翻訳しました。

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

「AppleEventsProgrammingGuide」(レガシーライブラリ内)の「ReturningErrorInformation」を参照してください。

于 2013-03-13T13:21:00.950 に答える