I’m working on a camera app that records video, for that purpose, the app has to take into account the fact that the user might rotate his phone before starting a capture. So, before starting the recording, im getting the AVCaptureConnection
associated with my active AVCaptureVideoDataOutput
and setting connection’s videoOrientation
depending on device orientation. However, if the torch is on, this causes the torch to turn off.
Here’s the code snippet for setting orientation on the connection:
let orientation = UIDevice.current.orientation
let connection = videoDataOutput?.connection(with: .video)
var rotationAngle: CGFloat
var videoOrientation: AVCaptureVideoOrientation
switch orientation {
case .portrait:
rotationAngle = 0
videoOrientation = .portrait
case .landscapeLeft:
rotationAngle = 90
videoOrientation = .landscapeRight
case .landscapeRight:
rotationAngle = -90
videoOrientation = .landscapeLeft
case .portraitUpsideDown:
rotationAngle = 180
videoOrientation = .portraitUpsideDown
default:
rotationAngle = 0
videoOrientation = .portrait
}
if #available(iOS 17.0, *) {
if connection?.isVideoRotationAngleSupported(rotationAngle) ?? false {
connection?.videoRotationAngle = rotationAngle
}
} else {
// Fallback on earlier versions
if connection?.isVideoOrientationSupported ?? false {
connection?.videoOrientation = videoOrientation
}
}
The native camera and other camera apps dont seem to have such issue, I’m also on iOS 16.6.1
Any help would be greatly appreciated!