SwiftyCam
SwiftyCam copied to clipboard
UI API called on a background thread
getVideoOrientation()
is invoked from a background thread
This code solves this:
fileprivate func getVideoOrientation() -> AVCaptureVideoOrientation {
var videoOrientation: AVCaptureVideoOrientation!
if shouldUseDeviceOrientation && deviceOrientation != nil {
switch deviceOrientation! {
case .landscapeLeft:
videoOrientation = .landscapeRight
case .landscapeRight:
videoOrientation = .landscapeLeft
case .portraitUpsideDown:
videoOrientation = .portraitUpsideDown
default:
videoOrientation = .portrait
}
} else {
DispatchQueue.main.sync {
videoOrientation = self.previewLayer!.videoPreviewLayer.connection.videoOrientation
}
}
return videoOrientation
}
Same premise here, but keeping the "guard"
fileprivate func getVideoOrientation() -> AVCaptureVideoOrientation {
guard shouldUseDeviceOrientation, let deviceOrientation = self.deviceOrientation else {
return DispatchQueue.main.sync {
return previewLayer!.videoPreviewLayer.connection!.videoOrientation
}
}
switch deviceOrientation {
case .landscapeLeft:
return .landscapeRight
case .landscapeRight:
return .landscapeLeft
case .portraitUpsideDown:
return .portraitUpsideDown
default:
return .portrait
}
}
Please pull this into the main branch.