@ -309,7 +309,7 @@ class ScannerViewModel: NSObject, ObservableObject, AVCaptureMetadataOutputObjec
if let readableObject = metadataObject as ? AVMetadataMachineReadableCodeObject ,
if let readableObject = metadataObject as ? AVMetadataMachineReadableCodeObject ,
let stringValue = readableObject . stringValue {
let stringValue = readableObject . stringValue {
let codeType = readableObject. type . rawValue
let codeType = getBarcodeTypeString( from : readableObject . type )
let bounds = readableObject . bounds
let bounds = readableObject . bounds
let detectedCode = DetectedCode (
let detectedCode = DetectedCode (
@ -390,4 +390,43 @@ class ScannerViewModel: NSObject, ObservableObject, AVCaptureMetadataOutputObjec
device . unlockForConfiguration ( )
device . unlockForConfiguration ( )
}
}
}
}
// MARK: - 条 形 码 类 型 转 换
// / 获 取 条 形 码 类 型 的 可 读 字 符 串
private func getBarcodeTypeString ( from metadataType : AVMetadataObject . ObjectType ) -> String {
switch metadataType {
case . ean8 :
return " EAN-8 "
case . ean13 :
return " EAN-13 "
case . upce :
return " UPC-E "
case . code39 :
return " Code 39 "
case . code93 :
return " Code 93 "
case . code128 :
return " Code 128 "
case . itf14 :
return " ITF-14 "
case . pdf417 :
return " PDF417 "
case . qr :
return " QR Code "
case . dataMatrix :
return " Data Matrix "
case . aztec :
return " Aztec "
default :
// 处 理 可 能 包 含 前 缀 的 类 型 字 符 串
let typeString = metadataType . rawValue
if typeString . contains ( " org.gs1. " ) {
// 移 除 o r g . g s 1 . 前 缀
let cleanType = typeString . replacingOccurrences ( of : " org.gs1. " , with : " " )
return cleanType . uppercased ( )
}
return typeString
}
}
}
}