title: How capture photo then iOS-app is minimized?
body: <p>How take picture from camera when iOS-app is minimized?<br>
  (i.e. after <code>applicationDidEnterBackground:</code> / <code>applicationWillResignActive:</code> )</p>
  
  <p><strong>AppDelegate.m:</strong> (<a href="https://stackoverflow.com/a/17591384/1309648">thank you link</a>)</p>
  
  <pre><code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  {
  
      //To make the code block asynchronous
      dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  
          //### background task starts
          NSLog(@"Running in the background\n");
          while(TRUE)
          {
              printf("Called"); //////Work fine
  
              [self.window.rootViewController captureNow]; /////Capture picture!
  
              [NSThread sleepForTimeInterval: 10.0]; //wait for 10 sec
          }
      });
  
      return YES;
  }
  </code></pre>
  
  <p><strong>OurViewController.m:</strong> (<a href="http://red-glasses.com/index.php/tutorials/ios4-take-photos-with-live-video-preview-using-avfoundation/" rel="nofollow noreferrer">thank you link</a>)</p>
  
  <pre><code>-(IBAction)captureNow {
  
      AVCaptureConnection *videoConnection = nil;
      for (AVCaptureConnection *connection in _stillImageOutput.connections)
      {
          for (AVCaptureInputPort *port in [connection inputPorts])
          {
              if ([[port mediaType] isEqual:AVMediaTypeVideo] )
              {
                  videoConnection = connection;
                  break;
              }
          }
          if (videoConnection)
          {
              break;
          }
      }
  
      NSLog(@"about to request a capture from: %@", _stillImageOutput);
      [_stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler: ^(CMSampleBufferRef imageSampleBuffer, NSError *error)
       {
           CFDictionaryRef exifAttachments = CMGetAttachment( imageSampleBuffer, kCGImagePropertyExifDictionary, NULL);
  
           if (error)
           {
               NSLog(@"ERROR = %@", error); ///// Error!
           }
  
           NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer]; ////SIGABRT, cause imageSampleBuffer is nil
           UIImage *image = [[UIImage alloc] initWithData:imageData];
  
           UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
  
           [image release];
       }];
  }
  </code></pre>
  
  <p>This code works fine, when application is active. But take error (SIGABRT), when app is minimized. </p>
  
  <p>Maybe are there other libraries can afford to do it?</p>