2009-07-16 80 views
2

在我的應用程序,我創建一個目錄,然後將下面的代碼工作:無法獲取FileCreationDate?

NSDictionary *fileAttributes = [fileManager fileAttributesAtPath:trackDirectory traverseLink:YES]; 
NSDate *fileDate = [fileAttributes objectForKey:NSFileModificationDate]; 

然而,當我嘗試並獲得NSFileCreationDate相反,這是行不通的。

我在做什麼錯?

回答

1

據我所見,iPhoneOS上沒有其他日期。這裏是整個attributesOfItemAtPath:的樣子:

{ 
    NSFileGroupOwnerAccountID = 20; 
    NSFileGroupOwnerAccountName = staff; 
    NSFileModificationDate = 2009-12-03 21:34:59 -0800; 
    NSFileOwnerAccountID = 501; 
    NSFileOwnerAccountName = username; 
    NSFilePosixPermissions = 420; 
    NSFileReferenceCount = 1; 
    NSFileSize = 8703; 
    NSFileSystemFileNumber = 14066295; 
    NSFileSystemNumber = 234881026; 
    NSFileType = NSFileTypeRegular; 
} 

那麼,你的答案是...你想訪問字典的鍵是不存在的iPhoneOS。

1

不確定何時添加它,但它取決於iOS版本。我已經在iOS 4.1中測試過,並得到:

{ 
    NSFileCreationDate = "2011-09-23 07:20:12 GMT"; 
    NSFileExtensionHidden = 0; 
    NSFileGroupOwnerAccountID = 501; 
    NSFileGroupOwnerAccountName = mobile; 
    NSFileModificationDate = "2011-09-23 07:20:48 GMT"; 
    NSFileOwnerAccountID = 501; 
    NSFileOwnerAccountName = mobile; 
    NSFilePosixPermissions = 420; 
    NSFileProtectionKey = NSFileProtectionNone; 
    NSFileReferenceCount = 1; 
    NSFileSize = 634880; 
    NSFileSystemFileNumber = 382807; 
    NSFileSystemNumber = 234881027; 
    NSFileType = NSFileTypeRegular; 
} 
0
It depends on iOS version. iOS 5 provides following detail 
{ 
    NSFileCreationDate = "2012-05-14 09:59:24 +0000"; 
    NSFileExtensionHidden = 0; 
    NSFileGroupOwnerAccountID = 20; 
    NSFileGroupOwnerAccountName = staff; 
    NSFileModificationDate = "2012-05-14 09:59:29 +0000"; 
    NSFileOwnerAccountID = 501; 
    NSFileOwnerAccountName = indianic; 
    NSFilePosixPermissions = 420; 
    NSFileReferenceCount = 1; 
    NSFileSize = 464357; 
    NSFileSystemFileNumber = 1732968; 
    NSFileSystemNumber = 234881027; 
    NSFileType = NSFileTypeRegular; 
}