Read binary QR Code with AVFoundation

前端 未结 3 1023
鱼传尺愫
鱼传尺愫 2020-12-10 03:05

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

I can get a AVMetadataMachineReadableCodeObject object of .type AV

相关标签:
3条回答
  • 2020-12-10 03:20

    I was able to solve this issue by Base64 encoding the data in the QR code. This obviously won't work if you're not also generating the QR codes but could be option for people that are.

    We were running into the upper limit of data that can be stored in a QR code but by compressing the data (we used zlib) and then Base64 encoding the compressed data, so long as your data compresses to less than 75% of its original size you get some additional capacity and can use the stringValue property to get your data back out, you just have to Base64 decode and then decompress to get the original data back.

    Even if you're starting with binary data that isn't very compressible, so long as you can handle the overhead of Base64 and still be within the limitations of QR codes this may be a viable option that avoids working around the fact that AVMetadataMachineReadableCodeObject seems to want to work with string values.

    0 讨论(0)
  • 2020-12-10 03:31

    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.

    0 讨论(0)
  • 2020-12-10 03:47

    You can use a CIDetector to get to a CIQRCodeFeature which has a symbolDescriptor which has a errorCorrectedPayload which contains the data.

    Only problem is that this data still includes QR code headers, like ECI etc... so you still need to interpret the bits.

    I summed it up in a post here.

    0 讨论(0)
提交回复
热议问题