有没有办法将 MicroQR 条形码添加为 AVMetadataObject.ObjectType?
Is there a way to add MicroQR barcodes as an AVMetadataObject.ObjectType?
我需要使用 iOS 设备上的摄像头扫描 MicroQR 条形码。有谁知道添加类型的本机方法?例如,我的内置常量看起来像这样:哦,是的,我正在使用 Swift
let supportedCodeTypes = [AVMetadataObject.ObjectType.upce, AVMetadataObject.ObjectType.code39,
AVMetadataObject.ObjectType.code39Mod43, AVMetadataObject.ObjectType.code93,
AVMetadataObject.ObjectType.code128, AVMetadataObject.ObjectType.ean8,
AVMetadataObject.ObjectType.ean13, AVMetadataObject.ObjectType.aztec,
AVMetadataObject.ObjectType.pdf417, AVMetadataObject.ObjectType.itf14,
AVMetadataObject.ObjectType.dataMatrix, AVMetadataObject.ObjectType.interleaved2of5,
AVMetadataObject.ObjectType.qr]
我在想我也许可以这样实现它:
let microqr = AVMetadataObject.ObjectType(rawValue: String)
然后我可以将它添加到我的数组中,但我不知道将什么作为 rawValue: 的字符串放置。当然,我什至不确定这是否可行。我真的很感激朝着正确的方向前进。谢谢
否 — AVCaptureMetadataOutput
的识别引擎在系统软件或硬件中,Apple 不提供 API 用于为新对象类型插入您自己的引擎。
你说得对,可以使用 init(rawValue: String)
初始值设定项和任意字符串构造 AVMetadataObject.ObjectType
类型的值。然而,AVCapture 系统只能作用于它知道的对象类型——AVMetadataObject.ObjectType
类型的其他值对于使用该类型的 API 是无意义的。 (我不确定这样的 API 是否会忽略未知 ObjectType
值或引发错误,但很容易检查...)
换句话说,调用 AVMetadataObject.ObjectType(rawValue: "someNewBarcodeStandard")
并没有教 AVCapture 如何识别那种条形码,就像 AVMetadataObject.ObjectType(rawValue: "")
教它如何识别鱼一样。
顺便说一下,Swift 类型推断意味着您不必写出每个 type/constant 名称的全称:
let supportedCodeTypes: [AVMetadataObject.ObjectType] = [.upce, .code39,
.code39Mod43, .code93,
.code128, .ean8,
.ean13, .aztec,
.pdf417, .itf14,
.dataMatrix, .interleaved2of5,
.qr]
我需要使用 iOS 设备上的摄像头扫描 MicroQR 条形码。有谁知道添加类型的本机方法?例如,我的内置常量看起来像这样:哦,是的,我正在使用 Swift
let supportedCodeTypes = [AVMetadataObject.ObjectType.upce, AVMetadataObject.ObjectType.code39,
AVMetadataObject.ObjectType.code39Mod43, AVMetadataObject.ObjectType.code93,
AVMetadataObject.ObjectType.code128, AVMetadataObject.ObjectType.ean8,
AVMetadataObject.ObjectType.ean13, AVMetadataObject.ObjectType.aztec,
AVMetadataObject.ObjectType.pdf417, AVMetadataObject.ObjectType.itf14,
AVMetadataObject.ObjectType.dataMatrix, AVMetadataObject.ObjectType.interleaved2of5,
AVMetadataObject.ObjectType.qr]
我在想我也许可以这样实现它:
let microqr = AVMetadataObject.ObjectType(rawValue: String)
然后我可以将它添加到我的数组中,但我不知道将什么作为 rawValue: 的字符串放置。当然,我什至不确定这是否可行。我真的很感激朝着正确的方向前进。谢谢
否 — AVCaptureMetadataOutput
的识别引擎在系统软件或硬件中,Apple 不提供 API 用于为新对象类型插入您自己的引擎。
你说得对,可以使用 init(rawValue: String)
初始值设定项和任意字符串构造 AVMetadataObject.ObjectType
类型的值。然而,AVCapture 系统只能作用于它知道的对象类型——AVMetadataObject.ObjectType
类型的其他值对于使用该类型的 API 是无意义的。 (我不确定这样的 API 是否会忽略未知 ObjectType
值或引发错误,但很容易检查...)
换句话说,调用 AVMetadataObject.ObjectType(rawValue: "someNewBarcodeStandard")
并没有教 AVCapture 如何识别那种条形码,就像 AVMetadataObject.ObjectType(rawValue: "")
教它如何识别鱼一样。
顺便说一下,Swift 类型推断意味着您不必写出每个 type/constant 名称的全称:
let supportedCodeTypes: [AVMetadataObject.ObjectType] = [.upce, .code39,
.code39Mod43, .code93,
.code128, .ean8,
.ean13, .aztec,
.pdf417, .itf14,
.dataMatrix, .interleaved2of5,
.qr]