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:
parent
00718ea0ee
commit
5d9d153e54
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user