Skip to content

Instantly share code, notes, and snippets.

@quietcricket
Created April 12, 2012 15:21
Show Gist options
  • Save quietcricket/2368138 to your computer and use it in GitHub Desktop.
Save quietcricket/2368138 to your computer and use it in GitHub Desktop.
IOS download image asynchronously and cache it
__block ASIHTTPRequest* req=[[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:url]];
req.cachePolicy=ASIOnlyLoadIfNotCachedCachePolicy;
req.downloadCache=[ASIDownloadCache sharedCache];
[req setCompletionBlock:^{
UIImage* img=[UIImage imageWithData:[req responseData]];
}];
[req setFailedBlock:^{
NSLog(@"Download Failed");
}];
[req startAsynchronous];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment