我想创建一个连接到iPhoto库的应用程序。所以现在我想从图书馆中阅读事件和图片本身。
有没有一种很好的/简单的方法来做到这一点,或者我必须手动读取iPhoto用户数据的包结构?
到目前为止,我只找到了一个拍照的人:Is there a UIImagePicker for the Mac Desktop
更新:我找到了另一个相关的SO帖子:Selecting iPhoto images within a cocoa application
发布于 2012-03-14 23:35:25
你可以用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];发布于 2013-11-04 18:30:38
如果在App Store上发布应用程序,您现在需要使用沙盒,这将停止以前的AppleScript方法( iPhoto应用程序启动,但返回一个空集)。
XML库由一个包含照片、数据库和iPhoto文件的目录结构组成。每个iPhoto版本的内容都会有所不同,因此手动访问这些文件时要小心。
如果您只想要专辑的详细信息,可以解析文件AlbumData.xml
如果你想要照片,你可以浏览“大师”文件夹。文件结构跟随日期,而不是iPhoto中配置的集。
在这里可以找到关于iPhoto库内部的更多信息:http://www.fatcatsoftware.com/iplm/Help/iphoto%20library%20internals.html
大多数数据库都是SQLite格式的,因此可以通过Objective C以编程方式访问,尽管您可以再次预期不同版本的iPhoto之间的模式变化。感兴趣的主要数据库是数据库/apdb中的Library.apdb和Properties.apdb。
如果你仍然想使用Apple Script方法,这里是之前答案的一个版本,其中包括Apple script执行部分:
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);
}https://stackoverflow.com/questions/8401054
复制相似问题