gpt4 book ai didi

objective-c - 以编程方式从 iPhoto 图库中读取

转载 作者:太空狗 更新时间:2023-10-30 03:51:24 24 4
gpt4 key购买 nike

我想创建一个连接到 iPhoto 图库的应用程序。所以现在我想从图书馆阅读事件和图片本身。

是否有一种优雅/简单的方法来执行此操作,还是我必须手动读取 iPhoto 用户数据的捆绑结构?

到目前为止我只找到了一个拍照者:Is there a UIImagePicker for the Mac Desktop

更新:我找到了另一个相关的 SO 帖子:Selecting iPhoto images within a cocoa application

最佳答案

你可以用 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];

关于objective-c - 以编程方式从 iPhoto 图库中读取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8401054/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com