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

modified to run captureSession.startRunning() on a background thread #378

Merged
merged 3 commits into from
Feb 26, 2024
Merged
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
28 changes: 20 additions & 8 deletions Sources/WeScan/Scan/CaptureSessionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,19 +141,31 @@ final class CaptureSessionManager: NSObject, AVCaptureVideoDataOutputSampleBuffe

switch authorizationStatus {
case .authorized:
DispatchQueue.main.async {
self.captureSession.startRunning()
DispatchQueue.global(qos: .userInitiated).async { [weak self] in
self?.captureSession.startRunning()
DispatchQueue.main.async {
guard let self = self else { return }
self.isDetecting = true
}
}
isDetecting = true
case .notDetermined:
AVCaptureDevice.requestAccess(for: AVMediaType.video, completionHandler: { _ in
DispatchQueue.main.async { [weak self] in
self?.start()
AVCaptureDevice.requestAccess(for: AVMediaType.video, completionHandler: { [weak self] granted in
DispatchQueue.main.async {
guard let self = self else { return }
if granted {
self.start()
} else {
let error = ImageScannerControllerError.authorization
self.delegate?.captureSessionManager(self, didFailWithError: error)
}
}
})
default:
let error = ImageScannerControllerError.authorization
delegate?.captureSessionManager(self, didFailWithError: error)
DispatchQueue.main.async { [weak self] in
guard let self = self else { return }
let error = ImageScannerControllerError.authorization
self.delegate?.captureSessionManager(self, didFailWithError: error)
}
}
}

Expand Down