图片下载进度条
Posted
技术标签:
【中文标题】图片下载进度条【英文标题】:progress bar when downloading image 【发布时间】:2010-06-24 19:10:56 【问题描述】:我将如何添加一个进度条来下载大图像或任何文件?这是我的代码:
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *docsPath = [paths objectAtIndex:0];
NSString *downloadPath = [[[NSString alloc]initWithFormat:@"http://www.zzz.com/%@.jpg",chartFileName]autorelease];
NSString *savePath = [[[NSString alloc]initWithFormat:@"%@/%@.jpg",docsPath, chartFileName]autorelease];
NSURL *url = [[NSURL alloc]initWithString:downloadPath];
NSData *downloadedChartData = [NSData dataWithContentsOfURL:url];
[url release];
[downloadedChartData writeToFile:savePath atomically:YES];
【问题讨论】:
【参考方案1】:您可以在 NSURLConnection 调用中覆盖 connection:didReceiveData:。更多信息请看这里:
How to integrate NSURLConnection with UIProgressView?
【讨论】:
在“[NSData dataWithContentsOfURL:]”中没有明确的 NSURLConnection 调用,你能给出一个完整的下载进度实现的指针吗? 或现成的解决方案developers-life.com/progress-bar-download-file-on-iphone.html【参考方案2】:在后台运行一个选择器,检查图像的下载大小,并将其与所需大小进行比较。然后将进度条的百分比设置为已下载/必需。
【讨论】:
以上是关于图片下载进度条的主要内容,如果未能解决你的问题,请参考以下文章
AFHTTPSessionManager下载文件 及下载中 进度条处理,进度条处理需要特别注意,要加载NSRunLoop 中