Skip to content

Commit

Permalink
Merge pull request #378 from hajunho/master
Browse files Browse the repository at this point in the history
modified to run captureSession.startRunning() on a background thread
  • Loading branch information
AvdLee authored Feb 26, 2024
2 parents cbf24f3 + 94ed306 commit cf918f7
Showing 1 changed file with 20 additions and 8 deletions.
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

0 comments on commit cf918f7

Please sign in to comment.