4

I'm trying to use http://github.com/TheLevelUp/ZXingObjC to create QR codes on my Mac app.

It works for every barcode types, but returns nil on QRcode! both 'result' and 'error' is empty. here's 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 on it?

Peter Hosey
  • 95,783
  • 15
  • 211
  • 370
Shahin
  • 865
  • 6
  • 21
  • Could you split out your QR code code into a sample Mac app that shows this problem? The sample app in the project is an iOS app and works for me. – Peter Hosey Apr 16 '13 at 23:05
  • Sure Peter, the sample iOS sample works for me, but on mac, it doesn't create the barcode! I'll create a sample project and post it here to test this. – Shahin Apr 18 '13 at 07:49

2 Answers2

4

I had the same issue. Here is workaround for this.

  1. Open file ZXingObjC\qrcode\encoder\ZXEncoder.m

  2. Find this row: int minPenalty = NSIntegerMax;. There must be a warning on it: Implicit conversion from 'long' to 'int' changes 9223372036854775807 to -1. That's the reason of the problem. NSIntegerMax returns 9223372036854775807 on my 64-bit Mac and minPenalty gets -1 value (since int type cannot store such a big number).

  3. Replace the NSIntegerMax by INT_MAX. It should return the correct value: 2147483647. That's the number NSIntegerMax returns on 32-bit machines according to the answer to this question.

  4. Run the app and you'll get your QR code!

Community
  • 1
  • 1
Andrey Gordeev
  • 30,606
  • 13
  • 135
  • 162
0

Try to use another method, not this with HINTS, use just:
[writer encode:@"yourmeganumber" format:kBarcodeFormatQRCode width:xxxx height:xxxx error:&error];

This works for me
Try and let me know

Daniel Arantes Loverde
  • 2,317
  • 2
  • 28
  • 41