Мне нужно получить дату изменения файла удаленного файла.
Очевидно, attributes
в этом примере возвращает NULL :
- (BOOL) fileHasBeenModifiedSinceLastLaunch
{
NSError * err = nil;
NSDictionary * attributes = [FILEMANAGER attributesOfItemAtPath:[NSURL URLWithString:@"http://www.wrightscs.com/some_file.txt"] error:&err];
NSString * modified = [NSString stringWithFormat:@"%@",[attributes objectForKey:@"NSFileModificationDate"]];
NSString * savedmod = [[NSUserDefaults standardUserDefaults] objectForKey:@"kFeedLastModified"];
NSLog(@"Error: %@",[err localizedDescription]);
NSLog(@"Saved Modified Date: %@", savedmod);
NSLog(@"Last Modified Date: %@", modified);
[[NSUserDefaults standardUserDefaults] setObject:modified forKey:@"kFeedLastModified"];
[[NSUserDefaults standardUserDefaults] synchronize];
if ( [savedmod isEqualToString:modified] )
{
NSLog(@"File has not been modified.");
return NO;
} else
{
NSLog(@"File has been modified.");
return YES;
}
}
Вывод:
2011-08-01 01:25:51.088 WrightsCS[2858:903] Error: The file “some_file.txt” couldn’t be opened because there is no such file.
2011-08-01 01:25:51.092 WrightsCS[2858:903] Saved Modified Date: (null)
2011-08-01 01:25:51.093 WrightsCS[2858:903] Last Modified Date: (null)
2011-08-01 01:25:51.095 WrightsCS[2858:903] Feed has not been modified.