Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change camera device types for handling device change on macro images #66

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions Sources/PhotoCaptureViewController/CaptureManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,16 @@ private extension CaptureManager {
}
cameraDevice.unlockForConfiguration()
}

// Set zoomFactor to get default camera functionality
do {
try cameraDevice.lockForConfiguration()
} catch let error1 as NSError {
error = error1
self.delegate?.captureManager(self, didFailWithError: error1)
}
cameraDevice.videoZoomFactor = 2.0
cameraDevice.unlockForConfiguration()
}

self.session.startRunning()
Expand All @@ -286,16 +296,21 @@ private extension CaptureManager {
}

func cameraDeviceWithPosition(_ position: AVCaptureDevice.Position) -> AVCaptureDevice? {
let deviceTypes: [AVCaptureDevice.DeviceType]

if #available(iOS 11.2, *) {
deviceTypes = [.builtInTrueDepthCamera, .builtInDualCamera, .builtInWideAngleCamera]
} else {
deviceTypes = [.builtInWideAngleCamera]
}

let discoverySession = AVCaptureDevice.DiscoverySession(deviceTypes: deviceTypes, mediaType: .video, position: .unspecified)
let availableCameraDevices = discoverySession.devices
let discoverySession = AVCaptureDevice.DiscoverySession(
deviceTypes: [
.builtInTripleCamera,
.builtInDualCamera,
.builtInTrueDepthCamera,
.builtInDualWideCamera,
.builtInWideAngleCamera
],
mediaType: .video,
position: .back
).devices

let availableCameraDevices = discoverySession
.filter { $0.isConnected && !$0.isSuspended }

guard availableCameraDevices.isEmpty == false else {
print("Error no camera devices found")
Expand Down