Skip to content

Commit

Permalink
Merge pull request #14 from yhkaplan/feature/fix-prevent-from-duplica…
Browse files Browse the repository at this point in the history
…ted-call

prevent from duplicated calling delegate methods
  • Loading branch information
po-miyasaka authored Aug 5, 2020
2 parents 6f91e04 + 4e59f70 commit 18ebe35
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Sources/CreditCardScanner/CameraView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ extension CameraView: AVCaptureVideoDataOutputSampleBufferDelegate {

guard let pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else {
delegate?.didError(with: CreditCardScannerError(kind: .capture))
delegate = nil
return
}

Expand All @@ -212,6 +213,7 @@ extension CameraView: AVCaptureVideoDataOutputSampleBufferDelegate {
guard let fullCameraImage = cgImage,
let croppedImage = fullCameraImage.cropping(to: regionOfInterest) else {
delegate?.didError(with: CreditCardScannerError(kind: .capture))
delegate = nil
return
}

Expand Down
2 changes: 2 additions & 0 deletions Sources/CreditCardScanner/ImageAnalyzer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ final class ImageAnalyzer {
} catch {
let e = CreditCardScannerError(kind: .photoProcessing, underlyingError: error)
delegate?.didFinishAnalyzation(with: .failure(e))
delegate = nil
}
}

Expand Down Expand Up @@ -124,6 +125,7 @@ final class ImageAnalyzer {

if strongSelf.selectedCard.number != nil {
strongSelf.delegate?.didFinishAnalyzation(with: .success(strongSelf.selectedCard))
strongSelf.delegate = nil
}
}
}
Expand Down

0 comments on commit 18ebe35

Please sign in to comment.