Created
September 4, 2013 09:17
-
-
Save zhangwc/6434662 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 自定义缓存设置 | |
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