I am using AVFoundation to capture a photo. This was all working fine, then I realized all the photos were saving to the photo library in portrait mode. I wanted them to save in the orientation the device was in when the camera took the picture, much as the built in camera app does on iOS. So I added this code:
if let videoConnection = photoOutput.connection(with: .video),
videoConnection.isVideoOrientationSupported {
// From() is just a helper to get video orientations from the device orientation.
videoConnection.videoOrientation = .from(UIDevice.current.orientation)
print("Photo orientation set to \(videoConnection.videoOrientation).")
}
With this addition, the first photo taken after a device rotation logs this error in the debugger:
<<<< FigCaptureSessionRemote >>>> Fig assert: "err == 0 " at bail (FigCaptureSessionRemote.m:866) - (err=-12784)
Subsequent photos will not repeat the error. Once you rotate the device again, same behavior. Photos taken after the app loads, but before any rotations have been made, do not produce this error.
I have tried many things, no dice. If I comment this code out it works without error, but of course the photos are all saved in portrait mode again.