Create QR Barcodes with ZXingObjC on Mac

I am trying to use http://github.com/TheLevelUp/ZXingObjC to create QR codes in my Mac application.

It works for every type of barcode, but returns zero on a QR code! "result" and "error" are empty. here is my code:

NSError* error = nil; ZXMultiFormatWriter* writer = [[ZXMultiFormatWriter alloc] init]; ZXBitMatrix* result = [writer encode:@"12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678" format:kBarcodeFormatQRCode width:1750 height:1750 hints:[[ZXEncodeHints alloc] init] error:&error]; if (result) { CGImageRef image = [[ZXImage imageWithMatrix:result] cgimage]; self.image.image = [[NSImage alloc] initWithCGImage:image size:NSMakeSize(1750, 1750)]; } else { NSLog(@"error: %@", error); } 

What's wrong?

+4
source share
2 answers

I had the same problem. Here is a workaround for this.

  • Open the file ZXingObjC\qrcode\encoder\ZXEncoder.m

  • Find this line: int minPenalty = NSIntegerMax; . There should be a warning on it: Implicit conversion from 'long' to 'int' changes 9223372036854775807 to -1 . This is the cause of the problem. NSIntegerMax returns 9223372036854775807 on my 64-bit Mac and minPenalty gets a value of -1 (since the int type cannot store such a large number).

  • Replace NSIntegerMax with INT_MAX . It should return the correct value: 2147483647 . That the NSIntegerMax number is returned on 32-bit machines in accordance with the answer to this question .

  • Launch the application and you will receive your QR code!

+4
source

Try using a different method, not this with HINTS, use only:
[writer encode:@"yourmeganumber" format:kBarcodeFormatQRCode width:xxxx height:xxxx error:&error];

It works for me
Give it a try and let me know.

0
source

All Articles