0

I am looking for uploading about 100 images in the background using AFNetworking ,do I need to create an operations queue? or I can create multiple request in a for loop like so:

    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer.acceptableContentTypes = nil;
    [manager.requestSerializer setTimeoutInterval:30.0];

    for(MyImageView *myImageView in images){
        NSDictionary *parameters = _PARAMETERS;
        [manager POST:@"//MY_URL_" parameters:parameters
        constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
            [formData appendPartWithFileData:UIImageJPEGRepresentation(myImageView.image, 0.65) name:@"NAME" fileName:@"name" mimeType:@"image/jpeg"];
        }progress:^(NSProgress * _Nonnull uploadProgress) {

        } success:^(NSURLSessionTask *task, id responseObject) {
            NSDictionary *response = (NSDictionary *)responseObject;
            dispatch_async(dispatch_get_main_queue(), ^{
                int success = [[response objectForKey:@"success"] intValue];
                if(success == 1) {
                    NSLog(@"IMAGE UPLOAD SUCCESSFULL");
                }
                else if (success == 0){
                    NSLog(@"IMAGE UPLOAD FAILED");
                }
                NSLog(@"%@",response);
            });
        } failure:^(NSURLSessionTask *operation, NSError *error) {
            NSLog(@"%@",error.localizedDescription);
        }];
    }

How do I create an NSOperations Queue if need be?

Thanks

pranav r
  • 1
  • 2
  • https://stackoverflow.com/questions/34753816/afnetworking-3-0-afhttpsessionmanager-using-nsoperation – Mukesh Sep 27 '17 at 09:56

1 Answers1

0

Use AFHTTPRequestOperation and NSOperarationQueue with NSOperationQueueDefaultMaxConcurrentOperationCount

ObranS
  • 200
  • 2
  • 10