I was wondering how to check and update a file for my iPhone using ASIHTTP
so far i have:
__block BOOL complete = NO;
__block BOOL failed = NO;
/* doing the actual check. replace your existing code with this. */
NSURL *url = [NSURL URLWithString:@"http://notasdasd.com/file.txt"];
ASIHTTPRequest *request = [[ASIHTTPRequest alloc] initWithURL:url];
[request setDownloadCache:[ASIDownloadCache sharedCache]];
[request setCachePolicy:ASIAskServerIfModifiedCachePolicy|ASIFallbackToCacheIfLoadFailsCachePolicy];
[request setCompletionBlock:^{complete = YES;}];
[request setFailedBlock:^{failed = YES;}];
[request startSynchronous];
NSString *latestText = [request responseString];
And I want to check the old version in cache directory and compare the last modified of the headers to the modified date of the file in cache directory and then replace.
try something like this:
if([[NSFileManager defaultManager] fileExistsAtPath:filePath]){
NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:&error];
NSDate *fileDate =[dictionary objectForKey:NSFileModificationDate];
NSDate *today =[NSDate date];
if (![[[today dateByAddingTimeInterval:-(60*60*24)] earlierDate:fileDate] isEqualToDate:fileDate]) {
//file is less than 24 hours old, use this file.
}
else{
//file is older than 24 hours, replace it
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With