From 2666ac53a6273d1898f2b03985320d2d017b3e08 Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Wed, 18 Oct 2023 18:25:30 +0200 Subject: [PATCH] fix: Fix build on Xcode 14 (#2033) * fix: Fix build on Xcode 14 * Format * Make CI run on `macOS-latest` * Nested if --- .github/workflows/build-ios.yml | 4 ++-- .github/workflows/validate-ios.yml | 2 +- package/ios/CameraDevicesManager.swift | 16 +++++++------ .../Extensions/AVCaptureOutput+mirror.swift | 24 ++++++++++++------- 4 files changed, 27 insertions(+), 19 deletions(-) diff --git a/.github/workflows/build-ios.yml b/.github/workflows/build-ios.yml index 58c878c..71ebaa0 100644 --- a/.github/workflows/build-ios.yml +++ b/.github/workflows/build-ios.yml @@ -21,7 +21,7 @@ on: jobs: build: name: Build iOS Example App - runs-on: macOS-13 + runs-on: macOS-latest defaults: run: working-directory: package/example/ios @@ -80,7 +80,7 @@ jobs: build-no-frame-processors: name: Build iOS Example App without Frame Processors - runs-on: macOS-13 + runs-on: macOS-latest defaults: run: working-directory: package/example/ios diff --git a/.github/workflows/validate-ios.yml b/.github/workflows/validate-ios.yml index 65366df..e4870c7 100644 --- a/.github/workflows/validate-ios.yml +++ b/.github/workflows/validate-ios.yml @@ -27,7 +27,7 @@ jobs: env: WORKING_DIRECTORY: ios SwiftFormat: - runs-on: macOS-13 + runs-on: macOS-latest defaults: run: working-directory: ./package/ios diff --git a/package/ios/CameraDevicesManager.swift b/package/ios/CameraDevicesManager.swift index a65bcaf..3547ebc 100644 --- a/package/ios/CameraDevicesManager.swift +++ b/package/ios/CameraDevicesManager.swift @@ -38,13 +38,15 @@ class CameraDevicesManager: RCTEventEmitter { override func constantsToExport() -> [AnyHashable: Any]! { let devices = getDevicesJson() - let preferredDevice: [String: Any]? - if #available(iOS 17.0, *), - let userPreferred = AVCaptureDevice.userPreferredCamera { - preferredDevice = userPreferred.toDictionary() - } else { - preferredDevice = devices.first - } + let preferredDevice = devices.first + + #if swift(>=5.9) + if #available(iOS 17.0, *) { + if let userPreferred = AVCaptureDevice.userPreferredCamera { + preferredDevice = userPreferred.toDictionary() + } + } + #endif return [ "availableCameraDevices": devices, diff --git a/package/ios/Extensions/AVCaptureOutput+mirror.swift b/package/ios/Extensions/AVCaptureOutput+mirror.swift index fa0a8e5..5068386 100644 --- a/package/ios/Extensions/AVCaptureOutput+mirror.swift +++ b/package/ios/Extensions/AVCaptureOutput+mirror.swift @@ -32,20 +32,26 @@ extension AVCaptureOutput { func setOrientation(_ orientation: Orientation) { // Set orientation for each connection connections.forEach { connection in - if #available(iOS 17.0, *) { - // Camera Sensors are always in landscape rotation (90deg). - // We are setting the target rotation here, so we need to rotate by landscape once. - let cameraOrientation = orientation.rotateBy(orientation: .landscapeLeft) - let degrees = cameraOrientation.toDegrees() + #if swift(>=5.9) + if #available(iOS 17.0, *) { + // Camera Sensors are always in landscape rotation (90deg). + // We are setting the target rotation here, so we need to rotate by landscape once. + let cameraOrientation = orientation.rotateBy(orientation: .landscapeLeft) + let degrees = cameraOrientation.toDegrees() - if connection.isVideoRotationAngleSupported(degrees) { - connection.videoRotationAngle = degrees + if connection.isVideoRotationAngleSupported(degrees) { + connection.videoRotationAngle = degrees + } + } else { + if connection.isVideoOrientationSupported { + connection.videoOrientation = orientation.toAVCaptureVideoOrientation() + } } - } else { + #else if connection.isVideoOrientationSupported { connection.videoOrientation = orientation.toAVCaptureVideoOrientation() } - } + #endif } } }