Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read binary QR Code with AVFoundation

Tags:

ios

qr-code

Is it possible to read a binary encoded QR code with AVFoundation?

I can get a AVMetadataMachineReadableCodeObject object of .type AVMetadataObjectTypeQRCode, however this only has a stringValue property, which won't work, because the data contained in the QR code can't be converted to a string friendly representation.

Should I use ZXing instead?

Thanks

like image 336
Michael Bates Avatar asked Sep 07 '15 00:09

Michael Bates


People also ask

Does QR code use binary?

The patterns within QR codes represent binary codes that can be interpreted to reveal the code's data. A QR reader can identify a standard QR code based on the three large squares outside the QR code.

Can a QR code be deciphered?

You can decode a QR Code by hand, but that would require an understanding of mask patterns and the algorithm used to identify the error correction level and encoding type of the QR Code. To decipher a QR Code, all you need is your smartphone's camera app to scan the QR Code to access the information it holds.

How do I view the contents of a QR code?

Scanning QR Codes with Android 8.0, 9.0, and 10.0 Point your camera at the QR Code. Hold down the “Home” button and swipe up to reveal the options at the bottom. Select “What's on my screen?” The short URL connected to the QR Code's information will then appear.


1 Answers

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.

like image 104
Alexandru Motoc Avatar answered Oct 17 '22 21:10

Alexandru Motoc