I am currently working on having a file update from a remote server. I am able to download the file and save it to the documents directory. The file has a “Last-Modified” tag and I am using it to check if the file needs to be updated. But my question is, how do you save the string with the tag for later use? Later I want to compare the saved string with the another string with the current “Last-Modified” tag. If they are equal the file doesn’t have to be updated but if they’re not equal I will download the new file.
Sorry for bad English, correct me and any help is appreciated. Have been struggling with this for a while!
EDIT:
NSDictionary *metaData = [test allHeaderFields];
//NSLog(@"%@", [metaData description]);
lastModifiedString = [metaData objectForKey:@"Last-Modified"];
NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
[standardUserDefaults setObject:lastModifiedString forKey:@"LastModified"];
[standardUserDefaults synchronize];
NSString *savedString = [[NSUserDefaults standardUserDefaults] stringForKey:@"LastModified"];
if (![lastModifiedString isEqualToString:savedString])
{
[self downloadNewFile];
}
Download link to files: Archive.zip
Use NSUserDefaults or Core Data to persist a value.
EDIT:
It is not working because you are saving the new value before retrieving it. You’ll need to move
above
Now you’ll be comparing the new file value against the old user defaults value.