我想在iOS應用程序中將多個圖像從URL下載到我的設備。在iOS應用程序中下載多個圖像應用程序
//
// ImageDownload.m
//
#import "ImageDownload.h"
@implementation ImageDownload {
int *position;
NSArray *downloableImages;
}
- (void)start:(NSArray *)images delegate:(id)delegate
{
position = 0;
downloableImages = images;
NSUInteger *count = ((NSUInteger *)[downloableImages count]);
NSLog(@"%d", count);
[self startDownload];
}
- (void)startDownload
{
NSUInteger *imageDataCount;
NSArray *image;
NSString *filename;
NSString *fileurl;
NSURLRequest *imageUrlRequest;
image = [downloableImages objectAtIndex:position];
NSLog(@"%d", position);
NSArray *imageData = [image valueForKey:@"image"];
imageDataCount = ((NSUInteger *)[imageData count]);
if (imageDataCount > 0) {
filename = [imageData objectAtIndex:0];
fileurl = [imageData objectAtIndex:1];
NSLog(@"%@", fileurl);
imageUrlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:fileurl]];
NSURLConnection *imageUrlConnection = [[NSURLConnection alloc] initWithRequest:imageUrlRequest delegate:self startImmediately:TRUE];
} else {
NSUInteger *count = ((NSUInteger *)[downloableImages count]);
if (((NSUInteger *)position) < ((NSUInteger *)count - 1)) {
position = position + 1;
[self startDownload];
}
}
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(@"finish image...");
NSUInteger *count = ((NSUInteger *)[downloableImages count]);
if (((NSUInteger *)position) < ((NSUInteger *)count - 1)) {
position = position + 1;
[self startDownload];
}
}
@end
現在......我只檢查下載和當前URL的位置, 已存在27個文件下載......但下載不是一個一個去查...此輸出:
位置:0
HTTP ..... fichero00.jpg
完成下載位置:4
HTTP ..... fichero04.jpg
完成下載位置:8
HTTP ..... fichero08.jpg
完成下載各地NSOperationQueue
嗨,我嘗試這種方法...工作正常下載...但我有問題,當我嘗試更新progressView! 「completionHandler」實際上是當下載完成時,因爲我有一個延遲時,progressView更新... – jfrubiom 2013-02-22 17:29:44
@jfrubiom你可以顯示你的完成處理程序部分的進度視圖 – Dany 2013-02-23 08:46:05
嗨,我在這裏重新提出我的問題http:///stackoverflow.com/questions/15037791/ios-some-problems-during-download-multiple-images-and-update-uiprogressview – jfrubiom 2013-02-23 13:39:47