fix: Fix Xcode 15 build error (var instead of let) (#2048)

* fix: Fix Xcode 15 build error (`var` instead of `let`)

* chore: Restructure code a bit for that logic

* Update CameraDevicesManager.swift
This commit is contained in:
Marc Rousavy 2023-10-19 17:43:20 +02:00 committed by GitHub
parent 00718ea0ee
commit 5d9d153e54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -38,19 +38,11 @@ class CameraDevicesManager: RCTEventEmitter {
override func constantsToExport() -> [AnyHashable: Any]! { override func constantsToExport() -> [AnyHashable: Any]! {
let devices = getDevicesJson() let devices = getDevicesJson()
let preferredDevice = devices.first let preferredDevice = getPreferredDevice()
#if swift(>=5.9)
if #available(iOS 17.0, *) {
if let userPreferred = AVCaptureDevice.userPreferredCamera {
preferredDevice = userPreferred.toDictionary()
}
}
#endif
return [ return [
"availableCameraDevices": devices, "availableCameraDevices": devices,
"userPreferredCameraDevice": preferredDevice as Any, "userPreferredCameraDevice": preferredDevice?.toDictionary() as Any,
] ]
} }
@ -60,6 +52,19 @@ class CameraDevicesManager: RCTEventEmitter {
} }
} }
private func getPreferredDevice() -> AVCaptureDevice? {
#if swift(>=5.9)
if #available(iOS 17.0, *) {
if let userPreferred = AVCaptureDevice.userPreferredCamera {
// Return the device that was explicitly marked as a preferred camera by the user
return userPreferred
}
}
#endif
// Just return the first device
return discoverySession.devices.first
}
private static func getAllDeviceTypes() -> [AVCaptureDevice.DeviceType] { private static func getAllDeviceTypes() -> [AVCaptureDevice.DeviceType] {
var deviceTypes: [AVCaptureDevice.DeviceType] = [] var deviceTypes: [AVCaptureDevice.DeviceType] = []
deviceTypes.append(.builtInDualCamera) deviceTypes.append(.builtInDualCamera)