Fixing the Aztec decoder in Zxing (Obj-C) to return raw ByteArray
<p>I'm working on an iOS app that's supposed to decode a certain type of Aztec barcode (<a href="http://www.regensblog.com/wp-content/uploads/2009/03/munich_bolzano.pdf" rel="nofollow noreferrer">example</a>, PDF). I need the scanner to return the data on a low level, since it's zlib compressed and I need to decompress it afterwards. The built-in barcode scanner using <code>AVCapture</code> works fine for regular string data but <a href="https://stackoverflow.com/questions/34438301/override-the-stringvalue-property-of-avmetadatamachinereadablecodeobject-or-crea">fails in my case</a>.</p>

<p>I have turned to <code>Zxing</code>, or rather its <code>Objective C</code> port <a href="https://github.com/TheLevelUp/ZXingObjC" rel="nofollow noreferrer">ZXingObjC</a>, in the hope of being able to access the decoded barcode data before it gets turned into a string. I was half successful. The <code>ZXResult</code> returned does contain a <code>ZXByteArray</code> called <code>rawBytes</code>, but <strong>only</strong> for QR codes (for Aztec codes it's <code>nil</code>)! I looked inside <a href="https://github.com/TheLevelUp/ZXingObjC/blob/master/ZXingObjC/aztec/decoder/ZXAztecDecoder.m#L69-L85" rel="nofollow noreferrer">ZXAztecDecoder.m</a> and sure enough, the byte array is never populated, not even in the original <code>Zxing</code> code in <code>Java</code>.
Someone tried to fix it for the original library (<a href="https://github.com/zxing/zxing/pull/389" rel="nofollow noreferrer">Pull Request</a>, Line 80) by doing</p>

<pre><code>byte[] rawBytes = convertBoolArrayToByteArray(correctedBits);
</code></pre>

<p>I'd like to add the same functionality for <code>ZXingObjC</code>, but I'm stuck trying to convert the<code>ZXBoolArray</code> to a <code>ZXByteArray</code>. Here is the decode function as I envision it:</p>

<pre><code>- (ZXDecoderResult *)decode:(ZXAztecDetectorResult *)detectorResult error:(NSError **)error {
    self.ddata = detectorResult;
    ZXBitMatrix *matrix = [detectorResult bits];
    ZXBoolArray *rawbits = [self extractBits:matrix];
    if (!rawbits) {
        if (error) *error = ZXFormatErrorInstance();
        return nil;
    }

    ZXBoolArray *correctedBits = [self correctBits:rawbits error:error];
    if (!correctedBits) {
        return nil;
    }

    ZXByteArray *rawBytes = /* somehow turn correctedBits into ZXByteArray */;

    NSString *result = [[self class] encodedData:correctedBits];
    return [[ZXDecoderResult alloc] initWithRawBytes:rawBytes text:result byteSegments:nil ecLevel:nil];
}
</code></pre>

<p>If somebody knows how to do this or has an idea how to go about it, I'd appreciate it. If it works out, I'd like to contribute the code to <code>ZXingObjC</code>, so this won't bug people in the future. Thanks in advance!</p>