How to download image with AFNetworking 2.0?

后端 未结 3 927
臣服心动
臣服心动 2020-12-04 11:57

Appareantly there is no AFImageRequestOperation, but only AFImageResponseSerializer and frankly I don\'t get it or maybe I\'m just looking too long

3条回答
  •  春和景丽
    2020-12-04 12:39

    for old version, there is no responseSerializer, you can also

    AFHTTPRequestOperation *requestOperation = [[AFHTTPRequestOperation alloc] initWithRequest:urlRequest];
    //requestOperation.responseSerializer = [AFImageResponseSerializer serializer];
    [requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSLog(@"Response: %@", responseObject);
        _imageView.image = [UIImage imageWithData:responseObject];
    
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"Image error: %@", error);
    }];
    [requestOperation start];
    

提交回复
热议问题