NSString *savePath=[NSHomeDirectory() stringByAppendingPathComponent:@"Library/Caches"];//savepath
[newworkqueue setMaxConcurrentOperationCount:1];//设置下载队列属性,设置为1只允许下完一首再下另一首,默认是并行下载不分前后
[request setShouldContinueWhenAppEntersBackground:YES];//允许后台下载
[request setTimeOutSeconds:120];//超过这个时间才会被认定为失败
[request setNumberOfTimesToRetryOnTimeout:3];//超时加载后重试几次
[newworkqueue setRequestDidFinishSelector:@selector(singleDownloadFinished:)];//单个request完成
[queue setShouldCancelAllRequestsOnFailure:NO];//禁用若单个失败取消掉所有request的属性
[request clearDelegatesAndCancel]//取消一个异步请求
[request setFile:@"/Users/ben/Desktop/ben.jpg"forKey:@"photo"]//上传图片,利用延时加载。
ASIHTTPRequest-断点续传(下载) 参考链接
NSURL*url = [NSURLURLWithString:ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];NSString*downloadPath = @"/Users/ben/Desktop/asi.png";//当request完成时,整个文件会被移动到这里[request setDownloadDestinationPath:downloadPath];//这个文件已经被下载了一部分[request setTemporaryFileDownloadPath:@"/Users/ben/Desktop/asi.png.download"];[request setAllowResumeForFileDownloads:YES];[request startSynchronous];//整个文件将会在这里NSString*theContent = [NSStringstringWithContentsOfFile:downloadPath];
原文链接: http://www.xiaoyaoli.com/?p=916-(float)currentOffLineSize{//查看Library/Caches文件总大小,(MB)
NSString *savePath=[NSHomeDirectory() stringByAppendingPathComponent:@"Library/Caches"];
NSFileManager *filemgr;
NSArray *filelist;
int count;
float cacheSize = 0;
filemgr =[NSFileManager defaultManager];
filelist = [filemgr contentsOfDirectoryAtPath:savePath error:NULL];
count = [filelist count];
for (NSString *url in filelist) {
NSData *data = [filemgr contentsAtPath:[NSString stringWithFormat:@"%@/%@",savePath,url]];
NSLog(@"file url=%@",[NSString stringWithFormat:@"%@/%@",savePath,url]);
cacheSize = cacheSize + ([data length]/1000);
}
cacheSize = (cacheSize/1024);
return cacheSize;
}
详解ASIHTTPRequest断点续传功能及下载队列优化
1483

被折叠的 条评论
为什么被折叠?



