使用AVFoundation扫描PDF417条码 [英] Using AVFoundation to scan PDF417 barcodes

查看:96
本文介绍了使用AVFoundation扫描PDF417条码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个正常工作的iOS条码扫描器,它使用iOS 7中新的AVFoundation条码扫描类.我可以成功获取一维条码(例如UPC条码)的字符串表示形式,但我还需要扫描二维PDF417条码.

I have a working iOS barcode scanner using the new AVFoundation barcode scanning classes in iOS 7. I can successfully get a string representation of a 1D barcode (for example, a UPC barcode) but I also need to scan two dimensional PDF417 barcodes.

我似乎无法弄清楚如何获取存储在PDF417条码中的数据的字符串表示形式(或任何表示形式).扫描程序识别条形码并返回 AVMetadataMachineReadableCodeObject ,但是将stringValue消息发送到该对象将返回nil.文档中对该方法的说明为:

I can't seem to figure out how to get a string representation (or any representation) of the data stored in a PDF417 barcode. The scanner recognizes the barcode and returns a AVMetadataMachineReadableCodeObject but sending the stringValue message to this object returns nil. The description of that method from the documentation says:

此属性的值是通过根据机器可读代码的格式对二进制有效载荷进行解码而创建的NSString,如果无法创建字符串表示形式,则为nil

The value of this property is an NSString created by decoding the binary payload according to the format of the machine-readable code or nil if a string representation cannot be created

因此,似乎无法创建字符串表示形式.很好...但是我该怎么办?此类似乎没有其他方法可以返回原始数据或有关已扫描条形码的任何其他有用信息.

So it would appear that a string representation cannot be created. That's fine...but what do I do then? There doesn't seem to be any other method for this class that will return raw data or anything other useful information about the scanned barcode.

推荐答案

原始数据确实存在于您的AVMetadataMachineReadableCodeObject中,但无法通过公共获取器获得.

The raw data does exist in your AVMetadataMachineReadableCodeObject, but it's not available through a public getter.

但是,您可以使用KVO提取它,但是Apple可能会拒绝您的应用程序.另外,将来的iOS版本可能会更改其私有API,并且您的代码可能会无效(由于硬编码的私有密钥).

However, you can use KVO to extract it, but Apple might reject your app. Also, future iOS versions might change their private APIs and your code could become invalid (because of the hardcoded private keys).

迅速:

readableCodeObject.valueForKeyPath("_internal.basicDescriptor")!["BarcodeRawData"]

Objective-C

Objective-C

[readableCodeObject valueForKeyPath:@"_internal.basicDescriptor"][@"BarcodeRawData"];

我在iOS 8和9上对此进行了测试.

I tested this for iOS 8 and 9.

这篇关于使用AVFoundation扫描PDF417条码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆