title: iOS AVCaptureVideoPreviewLayer not showing in UIView?
body: <h3>The Problem</h3>
  
  <p>I have a <a href="https://developer.apple.com/library/ios/#samplecode/SquareCam/Introduction/Intro.html#//apple_ref/doc/uid/DTS40011190">sample application from Apple (SquareCam)</a> that I'm using as reference to create a custom interface for a camera. I'm using the AVFoundation framework. If I build and run the project from Apple, the app runs as expected. However, if I take the same code from that project and place it in a new project in Xcode, the video preview will not display. </p>
  
  <p>I have simplified the code down to the essential components to run a video preview layer. Again, this code runs fine as is in the Apple (SquareCam) project, but does not display in my new project. </p>
  
  <h3>The Code</h3>
  
  <pre class="lang-c prettyprint-override"><code>- (void)setupAVCapture {
      NSError *error = nil;
  
      AVCaptureSession *session = [AVCaptureSession new];
      if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
          [session setSessionPreset:AVCaptureSessionPreset640x480];
      else
          [session setSessionPreset:AVCaptureSessionPresetPhoto];
  
      // Select a video device, make an input
      AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
      AVCaptureDeviceInput *deviceInput = [AVCaptureDeviceInput deviceInputWithDevice:device error:&amp;error];
  
      if ([session canAddInput:deviceInput])
          [session addInput:deviceInput];
  
      previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
      [previewLayer setBackgroundColor:[[UIColor blackColor] CGColor]];
      [previewLayer setVideoGravity:AVLayerVideoGravityResizeAspect];
      CALayer *rootLayer = [previewView layer];
      [rootLayer setMasksToBounds:YES];
      [previewLayer setFrame:[rootLayer bounds]];
      [rootLayer addSublayer:previewLayer];
      [session startRunning];
  }
  
  - (void)viewDidLoad {
      [super viewDidLoad];
      [self setupAVCapture];
  }
  </code></pre>
  
  <h3>What Have I Tried?</h3>
  
  <p>I have all of the outlets set up correctly. I have all of the framework libraries in my build phase. Both projects are using storyboard. What's odd is that I am able to capture an image from the camera and even switch the source from front to back. But the preview will not display. The Apple project was not setup with ARC. So, I updated the project to use ARC. Again, runs great in the Apple project, but not in a new project.</p>
  
  <h3>Thoughts?</h3>
  
  <p>Any ideas on what the issue could be? Is there a project setting that could cause this?</p>