문제

내 응용 프로그램에는 "문서 열기"(odoc) 이벤트에 응답하는 코드가 있습니다.Mac OS X Tiger 및 Leopard에서는 다음 코드가 제대로 작동합니다.

- (void) handleOpenDocumentEvent:
    (NSAppleEventDescriptor*)event
    withReplyEvent:(NSAppleEventDescriptor*)replyEvent
{
    NSAppleEventDescriptor const *const dirObj =
        [event descriptorForKeyword:keyDirectObject];
    DescType const dirObjType = [dirObj descriptorType];

    if ( dirObjType == 'alis' ) {
        //
        // Open a single file.
        //
        NSData const *const data = [dirObj data];
        AliasHandle const fileHandle =
            reinterpret_cast<AliasHandle>( ::NewHandle( [data length] ) );
        if ( fileHandle ) {
            [data getBytes:*fileHandle];
            err = [self queueFile:fileHandle fromSender:senderSig];
        }
    } else if ( dirObjType == 'list' ) {
        //
        // Open multiple files.
        //
        AliasHandle fileHandle =
            reinterpret_cast<AliasHandle>( ::NewHandle( 0 ) );
        if ( fileHandle ) {
            int const numItems = [dirObj numberOfItems];
            for ( int i = 1; i <= numItems; ++i ) {
                NSData const *const data = [[dirObj descriptorAtIndex:i] data];
                ::SetHandleSize( reinterpret_cast<Handle>( fileHandle ), [data length] );
                if ( (err = ::MemError()) != noErr )
                    break;
                [data getBytes:*fileHandle];
                err = [self queueFile:fileHandle fromSender:senderSig];
                if ( err != noErr )
                    break;
            }
        }
    }
}

그러나 Mac OS X Snow Leopard에서는 이 코드가 작동하지 않습니다.다음은 Leopard 시스템의 AppleEvent 덤프입니다.

{ 1 } 'aevt':  aevt/odoc (i386){
          return id: 1012269061 (0x3c560005)
     transaction id: 0 (0x0)
  interaction level: 112 (0x70)
     reply required: 0 (0x0)
             remote: 0 (0x0)
      for recording: 0 (0x0)
         reply port: 150031 (0x24a0f)
  target:
    { 1 } 'psn ':  8 bytes {
      { 0x0, 0x655655 } (iPhoto)
    }
  fEventSourcePSN: { 0x0,0x655655 } (iPhoto)
  optional attributes:
    < empty record >
  event data:
    { 1 } 'aevt':  - 1 items {
      key '----' -
        { 1 } 'list':  - 1 elements {
          { 1 } 'alis':  326 bytes {
            /Users/pjl/Pictures/IMG_8501.JPG
          }
        }
    }
}

다음은 Snow Leopard 시스템의 AppleEvent 덤프입니다.

{ 1 } 'aevt':  aevt/odoc (i386){
          return id: 5173 (0x1435)
     transaction id: 0 (0x0)
  interaction level: 112 (0x70)
     reply required: 0 (0x0)
             remote: 0 (0x0)
      for recording: 0 (0x0)
         reply port: 81695 (0x13f1f)
  target:
    { 1 } 'psn ':  8 bytes {
      { 0x0, 0x17c17c } (iPhoto)
    }
  fEventSourcePSN: { 0x0,0x17c17c } (iPhoto)
  optional attributes:
    < empty record >
  event data:
    { 1 } 'aevt':  - 1 items {
      key '----' - 
        { 1 } 'list':  - 1 elements {
          { 1 } 'bmrk':  944 bytes {
                  000: 626f 6f6b  b003 0000  0000 0110  1000 0000     book............
                  001: c002 0000  0500 0000  0101 0000  5573 6572     ............User
                  002: 7300 0000  0300 0000  0101 0000  706a 6c00     s...........pjl.
                  003: 0800 0000  0101 0000  5069 6374  7572 6573     ........Pictures
                  004: 0e00 0000  0101 0000  6950 686f  746f 204c     ........iPhoto L
                  005: 6962 7261  7279 0000  0800 0000  0101 0000     ibrary..........
                  006: 4d6f 6469  6669 6564  0400 0000  0101 0000     Modified........
                  007: 3230 3037  0b00 0000  0101 0000  4a75 6e20     2007........Jun 
                  008: 392c 2032  3030 3700  0c00 0000  0101 0000     9, 2007.........
                  009: 494d 475f  3633 3837  2e6a 7067  2000 0000     IMG_6387.jpg ...
                  ....
                  058: 0000 0000  30f0 0000  3002 0000  0000 0000     ....0...0.......
          }
        }
    }
}

'alis' 유형은 새로운 Snow Leopard "북마크" 유형으로 대체되었습니다.이 코드를 다음과 같이 수정하려면 어떻게 해야 합니까?

a) 새로운 'bmrk' 유형을 테스트하고 처리합니다. 즉, 파일의 절대 경로를 얻습니다.
b) Tiger와 Leopard에 대한 작업을 계속합니다.

?

아니면 'alis' 구조를 포함하는 odoc 이벤트를 계속 원한다고 OS에 알릴 수 있는 방법이 있습니까?

도움이 되었습니까?

해결책

여기에 포함된 "북마크 데이터"는 Snow Leopard에 도입된 일부 새로운 CFURL 및/또는 NSURL API를 사용하여 처리할 수 있습니다. +[NSURL URLByResolvingBookmarkData:옵션:relativeToURL:bookmarkDataIsStale:오류] 이벤트 설명자에 포함된 북마크 데이터를 확인하는 데 사용할 수 있는 NSURL API입니다.

또한 다음을 사용하여 설명자를 별칭으로 강제할 수도 있습니다. coerceToDescriptorType: 메서드를 사용하여 그런 식으로 처리하면 Snow Leopard에 이에 대한 내장 강제 처리기가 포함되어 있는지 여부가 문서화되어 있지 않다고 생각했습니다(물론 그래야 할 것 같습니다).

Tiger/Leopard 호환성의 경우 해당 시스템 중 어느 쪽에서도 북마크 데이터가 전달되지 않으므로 새 NSURL 메서드를 호출하는 것은 문제가 되지 않습니다. 이전 시스템에서는 해당 코드 경로를 따르지 않기 때문입니다.

그런데 헤더 파일 "AEDataModel.h"에는 사용 중인 4개의 문자 코드에 대한 기호 상수가 포함되어 있으므로 다음을 사용할 수 있습니다. typeAlias 대신에 'alis', typeBookmark 대신에 'bmrk', 기타 등등.이는 코드를 좀 더 읽기 쉽게 만들고 컴파일러가 오타 등으로부터 사용자를 보호할 수 있게 해줍니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top