Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios6 nsfilemanager createFileAtPath导致NSFileCreationDate为空_Ios6_Nsfilemanager - Fatal编程技术网

Ios6 nsfilemanager createFileAtPath导致NSFileCreationDate为空

Ios6 nsfilemanager createFileAtPath导致NSFileCreationDate为空,ios6,nsfilemanager,Ios6,Nsfilemanager,我正在从一个json对象创建一个图像文件,文件创建成功,图像确实已经创建并可以显示。我想要一个进程,将检查文件是否仍然在缓存或tmp目录中,然后再下载图像。如果图像确实存在,那么我想检查文件的创建日期和修改日期属性,看看是否需要下载图像的新版本以保持最新。这就是问题所在 创建和修改日期属性为null。我甚至尝试手动设置属性,但它没有改变任何东西 下面是我用来创建文件的代码: NSString *fileName = [NSHomeDirectory() stringByAppendingPath

我正在从一个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];

我不确定下一步该怎么办。非常感谢您的帮助。

我发现了我的问题。这并不是因为没有设置修改和创建日期,而是因为我没有获得文件的正确属性集。结果是,我使用的代码获取的是文件所在路径的属性,而不是文件本身的属性。

@特洛伊木马如何设置创建日期属性?我找不到在
createFileAtPath
函数中设置属性的实际示例。我发现了我的问题。这并不是因为没有设置修改和创建日期,而是因为我没有获得文件的正确属性集。最后,我使用的代码是获取文件所在路径的属性,而不是文件本身@特洛伊木马默认情况下仍保留
属性:nil
会为文件生成
NSDate
,并将修改日期的初始值设置为创建日期。