在iOS 4中排队下载很多图像?

时间:2010-12-21 19:23:39

标签: iphone ipad ios4

现在是否有一些新的框架添加在iOS 4中做这样的事情?我知道我可以使用http://allseeing-i.com/,但这需要对我的代码进行大的更改,而宁愿使用我可以使用的内容。

编辑解决方案:
这是我最终得到的解决方案,它的工作方式就像3000多张图像的魅力一样:

int j = 0;
        do{
            NSLog(@"x = %i, items count: %i", j, [items count]);

            if ((int)[[self networkQueue] requestsCount] < 100) {

                NSString *url =[NSString stringWithFormat:@"http://images.myurl.com/skus/%@/%@_tn.jpg",[[[manufacturers objectAtIndex:i] ManufacturerID] stringValue], [[items objectAtIndex:j]  valueForKey:@"PhotoName"]];
                NSString *url2 =[NSString stringWithFormat:@"http://images.myurl.com/skus/%@/%@_lg.jpg",[[[manufacturers objectAtIndex:i] ManufacturerID] stringValue], [[items objectAtIndex:j]  valueForKey:@"PhotoName"]];

                ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:url]];
                [[self networkQueue] addOperation:request];

                ASIHTTPRequest *request2 = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:url2]];
                [[self networkQueue] addOperation:request2];

                if (j==0) {
                    [[self networkQueue] go];
                }
                j++;
            }
        }
        while(j < [items count]);

一次排队100,当它们脱落时我添加更多,看起来我的内存消耗开始稍微增加,因此它正在努力,但是在队列完成后它会下降。

1 个答案:

答案 0 :(得分:1)

可能需要对网络接口代码进行一些重新设计,但从长远来看,切换到ASI会获得回报。

(那是ASIHttpRequest,http://allseeing-i.com/Tags/ASIHTTPRequest