title: iOS: camera orientation
body: <p>I want to capture an image with the camera using AVCaptureSession. </p>
  
  <p>It works ok, I start the camera and I can get the output. However, I have some problems with video orientation when I rotate the device.</p>
  
  <p>First, I want to support landscape left and right orientations and may be portrait modes too later.</p>
  
  <p>I implement:</p>
  
  <pre><code>- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation{ 
  return UIInterfaceOrientationIsLandscapse(interfaceOrientation);
  }
  </code></pre>
  
  <p>When I rotate the device, it rotates the app from landscape left to landscape right or vice versa, but I only see the camera correctly when I'm on landscape left. When the app is on landscape right, the video is rotated by 180 degrees.</p>
  
  <p>Thank you very much.</p>
  
  <p><strong>Update:</strong></p>
  
  <p>I've tried Spectravideo328 answer but I have an error when I try to rotate the device and the app crash. This is the error:</p>
  
  <pre><code>[AVCaptureVideoPreviewLayer connection]: unrecognized selector sent to instance 0xf678210
  
  *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[AVCaptureVideoPreviewLayer connection]: unrecognized selector sent to instance 0xf678210'
  </code></pre>
  
  <p>The error occurs in this line:</p>
  
  <pre><code>AVCaptureConnection *previewLayerConnection=self.previewLayer.connection;
  </code></pre>
  
  <p>I put it inside shouldAutorotateToInterfaceOrientation method. 
  Do you know what could be the reason of this error?</p>
  
  <p>Thanks</p>