Skip to content

Commit e6631c6

Browse files
fix: Ambiguity between UPC-A and EAN-13 (#33)
* fix: Ambiguity between UPC-A and EAN-13 * chore: Update CHANGELOG
1 parent 59c83f4 commit e6631c6

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [Unreleased]
8+
9+
- Fix ambiguity between UPC-A and EAN-13 when hint is provided.
10+
711
## 2.0.0
812

913
**BREAKING CHANGE**: The signature of `scanBarcode` has been updated, both input and output.

OSBarcodeLib/Scanner/CameraManager/OSBARCCaptureOutputDecoder.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ private extension OSBARCCaptureOutputDecoder {
8888
DispatchQueue.main.async {
8989
if let bestResult = request.results?.first as? VNBarcodeObservation, bestResult.confidence > 0.9, let payload = bestResult.payloadStringValue {
9090
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)
91-
let format = OSBARCScannerHint.fromVNBarcodeSymbology(bestResult.symbology)
91+
let format = OSBARCScannerHint.fromVNBarcodeSymbology(bestResult.symbology, withHint: self.hint)
9292
self.scanResult = OSBARCScanResult(text: payload, format: format)
9393
}
9494
}

OSBarcodeLib/Scanner/Extensions/OSBARCScannerHint+VNBarcodeSymbology.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,16 @@ extension OSBARCScannerHint {
1010
}
1111
}
1212

13-
static func fromVNBarcodeSymbology(_ symbology: VNBarcodeSymbology) -> OSBARCScannerHint {
13+
static func fromVNBarcodeSymbology(_ symbology: VNBarcodeSymbology, withHint hint: OSBARCScannerHint? = nil) -> OSBARCScannerHint {
14+
if (symbology == .ean13) {
15+
// UPC-A and EAN-13 have similar format, and Apple Vision does not distinguish between the two
16+
// if a specific hint was provided, return that as the format
17+
switch hint {
18+
case .upcA: return .upcA
19+
case .ean13: return .ean13
20+
default: break
21+
}
22+
}
1423
return Self.hintMappings.first { (_, symbologies) in
1524
symbologies.contains(symbology)
1625
}?.key ?? .unknown

0 commit comments

Comments
 (0)