2011-12-06 1 views
5

iPhoto 보관함에 연결하는 응용 프로그램을 만들고 싶습니다. 이제는 도서관에서 직접 행사와 그림을 읽으 려합니다.iPhoto 라이브러리에서 프로그램으로 읽음

우아하고 쉬운 방법이 있습니까? 아니면 iPhoto 사용자 데이터의 번들 구조를 수동으로 읽어야합니까? Is there a UIImagePicker for the Mac Desktop

업데이트 :

지금까지 나는 단지 그림을 즐긴다을 발견 한 나는 또 다른 관련 SO 게시물을 발견 : Selecting iPhoto images within a cocoa application

답변

5

당신은 NSAppleScript 함께 할 수 있습니다. 이것은 내 앱에서 복사/붙여 넣기를 한 것입니다. 아이디어를 보여주기 위해 해킹 된 것입니다.

NSAppleEventDescriptor d = .. compile this script .. 
     @"tell application \"iPhoto\" to properties of albums" 

    for (int i = 0; i < [d numberOfItems]; i++) 
    { 
     NSAppleEventDescriptor *albumDesc = [d descriptorAtIndex:i]; 

     // <NSAppleEventDescriptor: 'ipal'{ 
     // 'ID ':4.265e+09, 
     // 'purl':'utxt'("http://www.flickr.com/photos/..."), 
     // 'pnam':'utxt'("Vacation"), 
     // 'alTy':'pubs', 
     // 'alCh':[ ], 
     // 'alPx':'msng' }> 

     NSString *albumName = [[albumDesc descriptorForKeyword:'pnam'] stringValue]; 
     NSString *albumId = [[albumDesc descriptorForKeyword:'ID '] stringValue]; 

지금 이제 샌드 박스를 사용하는 데 필요한 필수 앱 스토어에 애플리케이션을 출시,이 작업에서 이전의 애플 스크립트 방법을 멈 추면 당신은 이미지

NSString *scp = 
    [NSString stringWithFormat:@"tell application \"iPhoto\" to properties of photos of album id %@", 
    [album objectForKey:@"id"]]; 

NSAppleEventDescriptor *d = ... compile scp ... 

// 1 based!? 
for (int i = 1; i <= [d numberOfItems]; i++) 
{ 
    NSAppleEventDescriptor *photoDesc = [d descriptorAtIndex:i]; 

    // Yes.. this happens. Not sure why?! 
    if (!photoDesc) 
     continue; 

    // <NSAppleEventDescriptor: 'ipmr'{ 
    // 'pnam':'utxt'("IMG_0058.JPG"), 
    // 'pwid':768, 
    // 'pdim':[ 768, 1024 ], 
    // 'alti':1.79769e+308, 
    // 'filn':'utxt'("3133889525_10975ba071_b.jpg"), 
    // 'ipth':'utxt'("/Users/lagnat/Pictures/iPhoto Library/Masters/2010/11/10/20101110-002341/3133889525_10975ba071_b.jpg"), 
    // 'idat':'ldt '($F57C69C500000000$), 
    // 'rate':0, 
    // 'titl':'utxt'("IMG_0058.JPG"), 
    // 'phit':1024, 
    // 'itpt':'utxt'("/Users/lagnat/Pictures/iPhoto Library/Thumbnails/2010/11/10/20101110-002341/3133889525_10975ba071_b.jpg.jpg"), 
    // 'ID ':4.295e+09, 
    // 'lati':'msng', 
    // 'pcom':'utxt'(""), 
    // 'opth':'utxt'("/Users/lagnat/Pictures/iPhoto Library/Masters/2010/11/10/20101110-002341/3133889525_10975ba071_b.jpg"), 
    // 'lngt':'msng', 
    // 'tiln':'utxt'("3133889525_10975ba071_b.jpg.jpg") }> 

    NSString *path = [[photoDesc descriptorForKeyword:'ipth'] stringValue]; 
    NSString *imgname = [[photoDesc descriptorForKeyword:'pnam'] stringValue]; 
1

을 찾기 위해 같은 일을 할 수 iPhoto 응용 프로그램이 시작되지만 빈 세트가 반환됩니다.

iPhoto 보관함은 사진, 데이터베이스 및 XML 파일이 포함 된 디렉토리 구조로 구성됩니다. iPhoto의 각 버전마다 내용이 변경되므로 수동으로이 파일에 액세스하는 경우주의하십시오.

방금 ​​앨범 정보를 원하는 경우에 당신이 석사 폴더를 찾아 볼 수있는 사진을 원하는 경우

AlbumData.xml 파일을 구문 분석 할 수 있습니다. 파일 구조는 iPhoto에서 구성된 세트가 아니라 날짜를 따릅니다.

자세한 내용은 여기 iPhoto 보관함의 내부에서 찾을 수 있습니다 : 다시는 스키마 변경을 기대할 수 있지만, 데이터베이스의 대부분은 SQLite는 형식으로되어 있습니다 그래서 프로그래밍 오브젝티브 C를 통해 액세스 할 수 있습니다 http://www.fatcatsoftware.com/iplm/Help/iphoto%20library%20internals.html

iPhoto의 다른 버전간에. 중요한 데이터베이스는 Database/apdb의 Library.apdb와 Properties.apdb입니다.


여전히 애플 스크립트 방법을 사용하려는 경우, 여기에 포함 된 애플 스크립트 실행 부분 이전 대답의 버전입니다 :

NSAppleScript *script = [[NSAppleScript alloc] initWithSource:@"tell application \"iPhoto\" to properties of albums"]; 
NSAppleEventDescriptor *d = [script executeAndReturnError:nil]; 

NSLog(@"photo library count: %ld", (long)[d numberOfItems]); 

for (int i = 0; i < [d numberOfItems]; i++) 
{ 
    NSAppleEventDescriptor *albumDesc = [d descriptorAtIndex:i]; 

    NSString *albumName = [[albumDesc descriptorForKeyword:'pnam'] stringValue]; 
    NSLog(@"%@", albumName); 
}