title: AVCaptureSession with multiple orientations issue
body: <p>I am attempting to implement a barcode scanner. I have an AVCaptureSession that takes in video from AVCaptureDevice. I want to support all orientations. With the following code, when I run the app, everything is fine in the portrait orientation. However in landscape orientation, the view rotates but the video input does not. So I end up with a 90degree rotated video.</p>
  
  <p>When I implement -(NSUInteger)supportedInterfaceOrientations method, then everything gets locked to the portrait position. </p>
  
  <p>Can anyone tell me how I can fix this issue? </p>
  
  <pre><code>- (void)viewDidLoad
  {
      [super viewDidLoad];
      // Do any additional setup after loading the view, typically from a nib.
  
      [self setupCaptureSession];
  
      _previewLayer.frame = _previewView.bounds;
      _previewView.center = self.view.center;
      _previewView.backgroundColor = [UIColor redColor];
      [_previewView.layer addSublayer:_previewLayer];
  
      [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillEnterForeground:) name:UIApplicationWillEnterForegroundNotification object:nil];
  
      [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidEnterBackground:) name:UIApplicationDidEnterBackgroundNotification object:nil];
  }
  
  - (void)didReceiveMemoryWarning
  {
      [super didReceiveMemoryWarning];
      // Dispose of any resources that can be recreated.
  }
  
  -(void)viewDidAppear:(BOOL)animated
  {
      [super viewDidAppear:animated];
      [self startRunning];
  }
  
  -(void)viewWillDisappear:(BOOL)animated
  {
      [super viewWillDisappear:animated];
      [self stopRunning];
  }
  
  -(void) setupCaptureSession
  {
      if (_captureSession)
          return;
  
      _videoDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
  
      if (!_videoDevice)
      {
          NSLog(@"No video camera on this device");
          return;
      }
  
      _captureSession = [[AVCaptureSession alloc]init];
  
      _videoInput = [[AVCaptureDeviceInput alloc]initWithDevice:_videoDevice error:nil];
  
      if ([_captureSession canAddInput:_videoInput])
      {
          [_captureSession addInput:_videoInput];
      }
  
      _previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:_captureSession];
  
      _previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
  
  }
  
  -(void) startRunning
  {
      if (_running)
          return;
  
      [_captureSession startRunning];
      _running = YES;
  }
  
  - (void) stopRunning
  {
      if (!_running)
          return;
  
      [_captureSession stopRunning];
      _running = NO;
  }
  
  /*
  -(NSUInteger)supportedInterfaceOrientations
  {
      return UIInterfaceOrientationLandscapeLeft|UIInterfaceOrientationLandscapeRight|UIInterfaceOrientationPortrait|UIInterfaceOrientationPortraitUpsideDown;
  }
  
  */
  </code></pre>
  
  <p>Edit: </p>
  
  <p>I tried the following code but the previewLayer orientation is still upsidedown/sideways.</p>
  
  <pre><code>    [[NSNotificationCenter defaultCenter] addObserver:self
                                               selector:@selector(orientationChanged)
                                                   name:UIDeviceOrientationDidChangeNotification
                                                 object:nil];
  -(void) orientationChanged
  {
      if (self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
          [_previewLayer.connection setVideoOrientation:AVCaptureVideoOrientationPortraitUpsideDown];
  
      if (self.interfaceOrientation == UIInterfaceOrientationPortrait)
          [_previewLayer.connection setVideoOrientation:AVCaptureVideoOrientationPortrait];
  
      if (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft)
          [_previewLayer.connection setVideoOrientation:AVCaptureVideoOrientationLandscapeLeft];
  
      if (self.interfaceOrientation == UIInterfaceOrientationLandscapeRight)
          [_previewLayer.connection setVideoOrientation:AVCaptureVideoOrientationLandscapeRight];
  }
  </code></pre>