Using AVFoundation to scan PDF417 barcodes

别等时光非礼了梦想. 提交于 2020-01-14 13:46:06

问题


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.

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:

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.


回答1:


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

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).

Swift:

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

Objective-C

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

I tested this for iOS 8 and 9.



来源:https://stackoverflow.com/questions/20255989/using-avfoundation-to-scan-pdf417-barcodes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!