Reputation: 885
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?
Upvotes: 4
Views: 1244
Reputation: 32449
I had the same issue. Here is workaround for this.
Open file ZXingObjC\qrcode\encoder\ZXEncoder.m
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).
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.
Run the app and you'll get your QR code!
Upvotes: 4
Reputation: 2314
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
Upvotes: 0