Replacing AVCaptureVideoOrientation with AVCaptureDevice.RotationCoordinator

On iOS, working with a video feed, I am getting a yellow warning that:

"'AVCaptureVideoOrientation' was deprecated in iOS 17.0: Use AVCaptureDeviceRotationCoordinator instead".

But I haven't been able to figure out how to get AVCaptureDevice.RotationCoordinator to work, and I haven't found any example of its usage in the Developer Forums or on the wider internet (the one mention of it in a WWDC session doesn't provide illustration of its use). Can anyone offer a working example using Swift?

Replies

Hey @grb2007!

I solved similar issue with the following solution. It seems to be working correctly. Looking forward to get some feedback on correctness. Hope that helps!

 private func getAngle(_ orientation: UIDeviceOrientation) -> CGFloat? {
    switch orientation {
        case .landscapeRight: return 45
        case .portrait: return 90
        case .portraitUpsideDown: return 180
        default: return 0.0
    }
}

Usage

if let output = photoOutput.connection(with: .video), let angle = self.getAngle(self.orientation), output.isVideoRotationAngleSupported(angle) {
    output.videoRotationAngle = angle
}

I think that is a potentially useful approach for addressing orientation in some situations - so thank you - but it's not what is needed for replacing use of AVCaptureVideoOrientation. The warning associated with AVCaptureVideoOrientation specifically suggests using AVCaptureDevice.RotationCoordinator - we still just need an example of how to make that work.