title: Upload Photos one at a time with a JSON response
body: <p>I need some help trying to figure out some logic / best method.</p>
  
  <p>I have an iOS app that uploads pictures. I have a server that responds <strong><em>Success</em></strong> or <strong><em>Fail</em></strong> after each picture is uploaded.</p>
  
  <p>If I have 5 pictures waiting to be uploaded (maybe no internet access, or the user only wants to upload on WIFI), I need a way to upload each picture individually, wait for that picture to respond success or fail, (fail will try again) and then move on to the next picture, all on a background thread so the user can keep working.</p>
  
  <p>Now I have most of the queuing logic ready. The issue I am having a problem with is the doing each picture singularly, getting that JSON response (success || fail) then moving on to the next. </p>
  
  <p>I currently use:</p>
  
  <pre><code> if (photoQueue.count &gt; 0) {
  
          for (int i = 0; i &lt; photoQueue.count; i++) {
              if([self processPhoto:[photoQueue objectAtIndex:i]]){
                  [photoQueue removeObjectAtIndex:i];
              } else {
                    NSLog(@"PHOTO UPLOAD FAILED");
              }
  
          }
      }
  </code></pre>
  
  <p>Where process photo returns a <code>bool</code>, but this isn't working correctly and seems to duplicate photos or it misses photos altogether.</p>
  
  <p>I have toyed with the idea of BLOCKS, Doing the photo upload in there and parsing the json response and passing that back as the return BOOL. But I do not know enough about them to step through however many photos.</p>
  
  <pre><code>[self doPhotoUpload:^(BOOL succeeded, NSError *error) {
     //Do the photo upload here and parse the json response and pass that as the return BOOL
  }];
  </code></pre>
  
  <p>How do I step-by-step through each individual photo and upload?</p>