AVCapturePhotoOutput image orientation not changes.

Hello, I'm trying to replicate UIImagePickerController photo taking ability with AVFoundation. What I do:

  1. invoke `photoOutput.capturePhoto(with, delegate)
  2. in delegate method photoOutput(_:didFinishProcessingPhoto:error:)) I retrieve UIImage with photo.fileDataRepresentation()

The issue: Produced UIImage has imageOrientation == .right, always. At the same time if I use UIImagePickerController, and say put my iPhone in landscape right position then produced image in its delegate has correct imageOrientation == .down. How can I achieve the same results with AVFoundation given that my iPhone orientation is locked (so UIDevice.orientation will not work). So far my best guess that I need to use accelerometer for this but maybe I miss some setting which allows to recover correct image orientation?

Thank you.

AVCapturePhotoOutput image orientation not changes.
 
 
Q