title: Burst-mode with iPhone and AVFoundation
body: <p>I want to implement burst-mode (5 shots in rapid succession) using the AVFoundation framework, but am having difficulty.</p>
  
  <pre><code>for(int imgNum = 0; imgNum &lt; nImages; imgNum++)
  {
      float dT = imgNum*4.0 - (CFAbsoluteTimeGetCurrent() - startTime);
      NSLog(@"Waiting for %.02f seconds...\n",dT);
      [NSThread sleepForTimeInterval:dT];
      [self takeStill:videoConnection];
  }
  
  - takeStill:(AVCaptureConnection*)videoConnection
  {
      [stillOut captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler:^(CMSampleBufferRef imageSampleBuffer, NSError *error)
   {
       if(error)
           NSLog(@"%s",[[error localizedDescription] UTF8String]);
       NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer];
       // {...} Save as a png
   }];
  }
  </code></pre>
  
  <p>Taking one image this way works fine. Seemingly, sleeping the thread causes the completion handler to never fire until all <code>nImages</code> are taken, and the result is that <code>imageSampleBuffer</code> is NULL. What is the correct way to handle this?</p>