将文件添加到移动文档文件夹时获取日期?

时间:2012-01-14 13:27:00

标签: objective-c cocoa icloud

是否可以/当文件被添加到移动文档文件夹/ icloud时,是否有文件属性来获取日期?

1 个答案:

答案 0 :(得分:0)

我在stackoverflow的另一个问题中找到了答案:

Where does the Finder obtain the "date added" of an item in a folder?

添加日期的属性位于Spotlight元数据中:

NSDate *dateAdded(NSURL *url)
{
    NSDate *rslt = nil;
    MDItemRef inspectedRef = nil;

    inspectedRef = MDItemCreateWithURL(kCFAllocatorDefault, (CFURLRef)url);
    if (inspectedRef){
        CFTypeRef cfRslt = MDItemCopyAttribute(inspectedRef, (CFStringRef)@"kMDItemDateAdded");
        if (cfRslt) {
            rslt = (NSDate *)cfRslt;
        }
    }
    return rslt;
}