Skip to content

Instantly share code, notes, and snippets.

@zhangwc
Created September 4, 2013 09:17
Show Gist options
  • Save zhangwc/6434662 to your computer and use it in GitHub Desktop.
Save zhangwc/6434662 to your computer and use it in GitHub Desktop.
// 自定义缓存设置
ASIDownloadCache *imageCache = [[ASIDownloadCache alloc] init];
//设置缓存路径
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [paths objectAtIndex:0];
[self.imageCache setStoragePath:[documentDirectory stringByAppendingPathComponent:@"resource"]];
[self.imageCache setDefaultCachePolicy:ASIOnlyLoadIfNotCachedCachePolicy];
[self.imageCache clearCachedResponsesForStoragePolicy:ASICachePermanentlyCacheStoragePolicy];
// 设置请求
self.request = [ASIHTTPRequest requestWithURL:self.imageUrl];
[self.request setDelegate:self];
[self.request setShouldContinueWhenAppEntersBackground:YES];
[self.request setTimeOutSeconds:60.0f];
[self.request setDownloadCache:imageCache];
[self.request setCacheStoragePolicy:ASICachePermanentlyCacheStoragePolicy];
[self.request setDownloadProgressDelegate:progressView];
// 下载队列
ASINetworkQueue *networkQueue = [[ASINetworkQueue alloc] init];
[networkQueue reset];
[networkQueue setShouldCancelAllRequestsOnFailure:NO];
networkQueue.showAccurateProgress = YES;
// 添加请求到下载队列
[networkQueue addOperation:self.request];
// 执行下载
[networkQueue go];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment