ASIHTTPRequest is a library that encapsulates HTTP requests and a bunch of intuitive checks (such as proxy authentication, caching, etc.) in one neat class that is an extension NSURLRequest. I recommend using this, you can choose a caching policy from the possible options here . It looks like you want a ASIAskServerIfModifiedCachePolicyserver that always requests if there is a newer version, and only loads if it is newer (it checks Last-Modified:, as well as other headers). You can also combine this caching policy with ASIFallbackToCacheIfLoadFailsCachePolicyso that if the server crashes, the last saved version will still be used.
Code example:
#import "ASIHTTPRequest.h"
#import "ASIDownloadCache.h"
ASIHTTPRequest *request = [[ASIHTTPRequest alloc] initWithURL:myTxtFileURL];
[request setDownloadCache:[ASIDownloadCache sharedCache]];
[request setCachePolicy:ASIAskServerIfModifiedCachePolicy|ASIFallbackToCacheIfLoadFailsCachePolicy];
[request setCacheStoragePolicy:ASICachePermanentlyCacheStoragePolicy];
[request startSynchronous];
NSString *latestText = [request responseString];
[request release];
, [request startSynchronous], . :
[request startSynchronous], startSynchronous startAsynchronous. .
: , . , , , . :
ASIHTTPRequest *request = [[ASIHTTPRequest alloc] initWithURL:myTxtFileURL];
[request setDownloadCache:[ASIDownloadCache sharedCache]];
[request setCachePolicy:ASIAskServerIfModifiedCachePolicy|ASIFallbackToCacheIfLoadFailsCachePolicy];
[request setCacheStoragePolicy:ASICachePermanentlyCacheStoragePolicy];
NSStringEncoding encoding;
NSError *error = nil;
NSString *oldText =
[NSString stringWithContentsOfFile:[[ASIDownloadCache sharedCache] pathToCachedResponseDataForRequest:request]
usedEncoding:encoding
error:&error];
[request startSynchronous];
NSString *newText = [request responseString];
[request release];
, , , . , , Apple iOS Google . Apple - .