我正在从json对象创建一个图像文件,文件创建成功,图像确实已创建并可以显示。我想要一个进程,在下载映像之前检查文件是否仍在缓存或tmp目录中。如果图像确实存在,那么我想检查文件的创建日期和修改日期属性,以查看是否需要下载新版本的图像以使其保持最新。这就是问题所在。
创建和修改日期属性为null
。我甚至试图手动设置属性,它没有改变任何东西。
以下是我用来创建文件的代码:
NSString *fileName = [NSHomeDirectory() stringByAppendingPathComponent: [NSString stringWithFormat:@"tmp/%@",theFileName]];
BOOL filecreationSuccess =[fileManager createFileAtPath:fileName contents:myData attributes:nil];
if(filecreationSuccess == NO){
NSLog(@"Failed to create the file");
}
我甚至尝试添加代码,文件中的属性仍为null
:
NSDate *now = [NSDate date];
NSDictionary *createDateAttr = [NSDictionary dictionaryWithObjectsAndKeys: now, NSFileCreationDate,nil];
NSDictionary *modDateAttr = [NSDictionary dictionaryWithObjectsAndKeys: now, NSFileModificationDate, nil];
[fileManager setAttributes:modDateAttr ofItemAtPath:fileName error:&err];
[fileManager setAttributes:createDateAttr ofItemAtPath:fileName error:&err];
我不确定接下来该做什么。非常感谢任何帮助,谢谢。
答案 0 :(得分:0)
我发现了我的问题。并不是没有设置修改和创建日期,而是我没有为文件获取正确的属性集。结果是我正在使用的代码是获取文件所在路径的属性,而不是文件本身。