Filter out true-depth-camera in getAvailableCameraDevices

This commit is contained in:
Marc Rousavy 2021-03-17 15:30:17 +01:00
parent 84fb076bc4
commit 9f30348053
3 changed files with 10 additions and 11 deletions

View File

@ -89,7 +89,14 @@ final class CameraViewManager: RCTViewManager {
final func getAvailableCameraDevices(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
withPromise(resolve: resolve, reject: reject) {
let discoverySession = AVCaptureDevice.DiscoverySession(deviceTypes: getAllDeviceTypes(), mediaType: .video, position: .unspecified)
return discoverySession.devices.map {
let devices = discoverySession.devices.filter({
if #available(iOS 11.1, *) {
// exclude the true-depth camera. The True-Depth camera has YUV and Infrared, can't take photos!
return $0.deviceType != .builtInTrueDepthCamera
}
return true
})
return devices.map {
return [
"id": $0.uniqueID,
"devices": $0.physicalDevices.map(\.deviceType.descriptor),

View File

@ -23,14 +23,6 @@ extension AVCaptureDevice.DeviceType {
break
}
}
if #available(iOS 11.1, *) {
switch self {
case .builtInTrueDepthCamera:
return "true-depth-camera"
default:
break
}
}
switch self {
case .builtInDualCamera:
return "dual-camera"
@ -39,6 +31,7 @@ extension AVCaptureDevice.DeviceType {
case .builtInWideAngleCamera:
return "wide-angle-camera"
default:
// e.g. `.builtInTrueDepthCamera`
fatalError("AVCaptureDevice.Position has unknown state.")
}
}

View File

@ -15,9 +15,8 @@ export type PhysicalCameraDeviceType = 'ultra-wide-angle-camera' | 'wide-angle-c
* * `"dual-camera"`: A combination of wide-angle and telephoto cameras that creates a capture device.
* * `"dual-wide-camera"`: A device that consists of two cameras of fixed focal length, one ultrawide angle and one wide angle.
* * `"triple-camera"`: A device that consists of three cameras of fixed focal length, one ultrawide angle, one wide angle, and one telephoto.
* * `"true-depth-camera"`: A combination of cameras and other sensors that creates a capture device capable of photo, video, and depth capture.
*/
export type LogicalCameraDeviceType = 'dual-camera' | 'dual-wide-camera' | 'triple-camera' | 'true-depth-camera';
export type LogicalCameraDeviceType = 'dual-camera' | 'dual-wide-camera' | 'triple-camera';
/**
* Parses an array of physical device types into a single {@linkcode PhysicalCameraDeviceType} or {@linkcode LogicalCameraDeviceType}, depending what matches.