Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

- Fix ambiguity between UPC-A and EAN-13 when hint is provided.

## 2.0.0

**BREAKING CHANGE**: The signature of `scanBarcode` has been updated, both input and output.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private extension OSBARCCaptureOutputDecoder {
DispatchQueue.main.async {
if let bestResult = request.results?.first as? VNBarcodeObservation, bestResult.confidence > 0.9, let payload = bestResult.payloadStringValue {
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)
let format = OSBARCScannerHint.fromVNBarcodeSymbology(bestResult.symbology)
let format = OSBARCScannerHint.fromVNBarcodeSymbology(bestResult.symbology, withHint: self.hint)
self.scanResult = OSBARCScanResult(text: payload, format: format)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@ extension OSBARCScannerHint {
}
}

static func fromVNBarcodeSymbology(_ symbology: VNBarcodeSymbology) -> OSBARCScannerHint {
static func fromVNBarcodeSymbology(_ symbology: VNBarcodeSymbology, withHint hint: OSBARCScannerHint? = nil) -> OSBARCScannerHint {
if (symbology == .ean13) {
// UPC-A and EAN-13 have similar format, and Apple Vision does not distinguish between the two
// if a specific hint was provided, return that as the format
switch hint {
case .upcA: return .upcA
case .ean13: return .ean13
default: break
}
}
return Self.hintMappings.first { (_, symbologies) in
symbologies.contains(symbology)
}?.key ?? .unknown
Expand Down
Loading