title: Get Camera Preview to AVCaptureVideoPreviewLayer
body: <p>I was trying to get the camera input to show on a preview layer view.</p>
  
  <p>self.cameraPreviewView is tied to a UIView in IB</p>
  
  <p>Here is my current code that I put together from the AV Foundation Programming Guide. But the preview never shows</p>
  
  <pre><code>AVCaptureSession *session = [[AVCaptureSession alloc] init];
      session.sessionPreset = AVCaptureSessionPresetHigh;
  
      AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
  
      NSError *error = nil;
      AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&amp;error];
  
      if (!input) {
          NSLog(@"Couldn't create video capture device");
      }
      [session addInput:input];
  
  
          // Create video preview layer and add it to the UI
          AVCaptureVideoPreviewLayer *newCaptureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
          UIView *view = self.cameraPreviewView;
          CALayer *viewLayer = [view layer];
  
          newCaptureVideoPreviewLayer.frame = view.bounds;
  
          [viewLayer addSublayer:newCaptureVideoPreviewLayer];
  
          self.cameraPreviewLayer = newCaptureVideoPreviewLayer;
  
  
  
          [session startRunning];
  </code></pre>