我正在尝试确定是否(以及何时)我的应用的临时文件目录中的文件已被修改,但修改日期(文件属性中的NSFileModificationDate
)似乎始终与创建日期匹配({ {1}})。我有一些模糊的回忆,iOS中的文件系统不会更新修改日期,但我没有在任何地方找到记录。
任何人都可以确认(并且可能指向文档)iOS不会更新修改日期吗?
此外,还有其他一些方法可以确定文件是否已经改变了内容的散列并自己跟踪结果吗?
答案 0 :(得分:2)
我认为这仍然有效。取自Get directory contents in date modified order:
+ (NSDate*) getModificationDateForFileAtPath:(NSString*)path {
struct tm* date; // create a time structure
struct stat attrib; // create a file attribute structure
stat([path UTF8String], &attrib); // get the attributes of afile.txt
date = gmtime(&(attrib.st_mtime)); // Get the last modified time and put it into the time structure
NSDateComponents *comps = [[NSDateComponents alloc] init];
[comps setSecond: date->tm_sec];
[comps setMinute: date->tm_min];
[comps setHour: date->tm_hour];
[comps setDay: date->tm_mday];
[comps setMonth: date->tm_mon + 1];
[comps setYear: date->tm_year + 1900];
NSCalendar *cal = [NSCalendar currentCalendar];
NSDate *modificationDate = [[cal dateFromComponents:comps] addTimeInterval:[[NSTimeZone systemTimeZone] secondsFromGMT]];
[comps release];
return modificationDate;
}