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
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With