I am creating an image file from a json object and the file creation is successful and the image is indeed created and can be displayed. I want a process that will check if the file is still in cache or a tmp directory before downloading the image. If the image is indeed there then I want to check the creation date and modification date attributes of the file to see if I need to download a new version of the image to keep it up to date. This is where the problem comes in.
The creation and modification date attributes are null
. I've even attempted to manually set the attributes and it didn't change anything.
Here's the code I use to create the file:
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");
}
I have even tried adding the Code and the attributes on the file are still 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];
I am unsure of what to do next. Any help would be greatly appreciated, Thank you.
I have found my problem. It wasn't that the modification and creation dates weren't being set, but that I was not getting the correct set of properties for the file. It ended up being that the code I was using was getting the properties for the path that the file was in, not the file itself.