2012-05-16 3 views
3

내 앱의 임시 파일 디렉토리에있는 파일이 수정되었는지 여부를 확인하려고하지만 수정 날짜 (파일 속성에 NSFileModificationDate)가 항상 생성 날짜 (NSFileCreationDate)와 일치하는 것으로 보입니다. iOS의 파일 시스템이 수정 날짜를 업데이트하지 않는다는 모호한 기억이 있지만 어디서나 문서화 된 것을 발견하지 못했습니다.iOS가 파일 수정 날짜를 업데이트합니까?

iOS가 수정 날짜를 업데이트하지 않는다는 것을 누구든지 확인할 수 있습니까?

또한 파일의 내용이 변경되지 않았는지 확인하고 결과를 추적하는 다른 방법이 있습니까?

답변

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; 
} 
관련 문제