Created
June 8, 2018 05:46
-
-
Save simonkim/4c7a20fb978c9dfc350b6bb4c1512332 to your computer and use it in GitHub Desktop.
How to check if an iOS camera support 4K capture
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Does not require camera access permission | |
* Usage: | |
let tool = CaptureDeviceDiscovery() | |
let front = tool.videoCaptureDevice(at: .front)?.supportsSessionPreset(AVCaptureSession.Preset.hd4K3840x2160) ?? false | |
let back = tool.videoCaptureDevice(at: .back)?.supportsSessionPreset(AVCaptureSession.Preset.hd4K3840x2160) ?? false | |
self.labelStatusFront.text = front ? "Supported" : "Not supported" | |
self.labelStatusBack.text = back ? "Supported" : "Not supported" | |
*/ | |
class CaptureDeviceDiscovery { | |
@available(iOS 10.0, *) | |
func availableDeviceTypes() -> [AVCaptureDevice.DeviceType] { | |
var deviceTypes: [AVCaptureDevice.DeviceType] = [.builtInTelephotoCamera, .builtInWideAngleCamera] | |
// 10.2 | |
if #available(iOS 10.2, *) { | |
deviceTypes.append(.builtInDualCamera) | |
if #available(iOS 11.1, *) { | |
deviceTypes.append(.builtInTrueDepthCamera) | |
} | |
} | |
return deviceTypes | |
} | |
func videoCaptureDevice(at position: AVCaptureDevice.Position) -> AVCaptureDevice? { | |
var device: AVCaptureDevice? = nil | |
if #available(iOS 10, *) { | |
let deviceTypes = availableDeviceTypes() | |
let session = AVCaptureDevice.DiscoverySession(deviceTypes: deviceTypes, mediaType: .video, position: position) | |
device = session.devices.first | |
} else { | |
device = AVCaptureDevice.devices(for: AVMediaType.video).filter( { $0.position == position }).first | |
} | |
return device | |
} | |
} |
Thank you! Is it possible to use this code? I'll reference you.
Sure. As much as you want
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you! Is it possible to use this code? I'll reference you.