创建图像的下载队列

时间:2014-05-24 23:07:05

标签: ios download afnetworking afnetworking-2

我想在即将到来的图像中创建方法,并且所有这些都在队列中逐个下载。我使用AFNetworking 2.0。我想知道是否有任何预先创建的代码可以帮助我解决问题?

我的代码

    NSString *urlString = link;
    NSURL *url = [NSURL URLWithString:urlString];
    NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];

    AFHTTPRequestOperation *requestOperation = [[AFHTTPRequestOperation alloc] initWithRequest:urlRequest];
    requestOperation.responseSerializer = [AFImageResponseSerializer serializer];

    [requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {

        UIImage *image = responseObject;
        //here I seve image to disk and so on
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {

        DDLogError(@"FAIL download image: %@",error);
    }];

1 个答案:

答案 0 :(得分:0)

尝试使用dispatch_group:所有下载都分组到一个队列中并逐个下载

AFNetworking 2.0 download multiple images with completion