5

iPhoto ライブラリに接続するアプリケーションを作成したいと考えています。そこで、ライブラリーからイベントと写真自体を読みたいと思います。

これを行うエレガントで簡単な方法はありますか、それとも iPhoto ユーザー データのバンドル構造を手動で読み取る必要がありますか?

これまでのところ、写真撮影者しか見つかりませんでした: Mac デスクトップ用の UIImagePicker はありますか?

更新: 別の関連する SO 投稿を見つけました:ココア アプリケーション内で iPhoto 画像を選択する

4

2 に答える 2

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];
于 2012-03-14T15:35:24.813 に答える
1

App Store で App をリリースする場合、Sandbox を使用する必要があるため、以前の AppleScript メソッドは機能しなくなります (iPhoto アプリは起動しますが、空のセットが返されます)。

iPhoto ライブラリは、写真、データベース、および XML ファイルを含むディレクトリ構造で構成されています。内容は iPhoto のバージョンごとに変わるため、これらのファイルに手動でアクセスする場合は注意してください。

アルバムの詳細だけが必要な場合は、ファイル AlbumData.xml を解析できます

写真が必要な場合は、Masters フォルダーを参照できます。ファイル構造は、iPhoto で設定されたセットではなく、日付に従います。

詳細については、iPhoto ライブラリの内部を参照してください: http://www.fatcatsoftware.com/iplm/Help/iphoto%20library%20internals.html

データベースの大部分は SQLite 形式であるため、Objective C を介してプログラムでアクセスできますが、iPhoto の異なるバージョン間でスキーマが変更されることが予想されます。対象となる主なデータベースは、Database/apdb 内の Library.apdb と Properties.apdb です。


それでもApple Scriptメソッドを使用したい場合は、Appleスクリプト実行部分が含まれた以前の回答のバージョンを次に示します。

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);
}
于 2013-11-04T10:30:37.580 に答える