我有iOS应用程序。在文件目录中有一些文件。我需要检查这些文件是否已被编辑或替换。正确的做法是什么?我应该对文件进行某种哈希处理还是最后一次编辑时间(如何在iOS中获得该时间)还是有一些更好的方法来实现呢?
最佳答案
您可以使用以下代码获取文件修改日期:
NSFileManager* fileManager = [NSFileManager defaultManager];
NSDictionary* attributes = [fileManager attributesOfItemAtPath:path error:nil];
if (attributes != nil) {
NSDate *date = (NSDate*)[attributes objectForKey:NSFileModificationDate];
NSLog(@"Last modification date: %@", [date description]);
} else {
NSLog(@"Not found");
}
here您可以找到
attributesOfItemAtPath:error:
函数的文档,而here您可以获取的文件属性列表
关于iphone - 检查文件是否更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15189334/