diff --git a/CHANGELOG.md b/CHANGELOG.md index f419708..42e92dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/OSBarcodeLib/Scanner/CameraManager/OSBARCCaptureOutputDecoder.swift b/OSBarcodeLib/Scanner/CameraManager/OSBARCCaptureOutputDecoder.swift index 413f9bd..4cca08c 100644 --- a/OSBarcodeLib/Scanner/CameraManager/OSBARCCaptureOutputDecoder.swift +++ b/OSBarcodeLib/Scanner/CameraManager/OSBARCCaptureOutputDecoder.swift @@ -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) } } diff --git a/OSBarcodeLib/Scanner/Extensions/OSBARCScannerHint+VNBarcodeSymbology.swift b/OSBarcodeLib/Scanner/Extensions/OSBARCScannerHint+VNBarcodeSymbology.swift index 9e5efb6..03a6fe3 100644 --- a/OSBarcodeLib/Scanner/Extensions/OSBARCScannerHint+VNBarcodeSymbology.swift +++ b/OSBarcodeLib/Scanner/Extensions/OSBARCScannerHint+VNBarcodeSymbology.swift @@ -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