jverkoey/ObjQREncoder — Issue #8: Issues with Encoding large strings and size/correction params
Author: semephor
Created: 2011-10-18 22:58:30+00:00
State: open

I am also finding the same issues as many other people when the strings for encoding becomes large... using the parameters of size/correction level does not solve the problem.

Firstly, using the default function:

+ (UIImage *)encode:(NSString *)str;

Causes a memory problem for large strings as described by others. So then instead we need to call to other function:

+ (UIImage *)encode:(NSString *)str size:(int)size correctionLevel:(QRCorrectionLevel)level;

... which allows you to put in size and correction level.

However, the library does not seem to work using the QR spec for how many chars you can code with qr version/correction level as specified here:
http://www.denso-wave.com/qrcode/vertable1-e.html

So, no problem we write our own functions which can at least encode the string you are trying to pass in without causing the memory exception as below:

+(int) genSize:(NSString *) myString; {

int version = 4;

if ([myString length] > 0 && [myString length] <19){
version=2;
}

if ([myString length] >= 20 && [myString length] <33){
version=2;
}

if ([myString length] >= 34 && [myString length] <54){
version=3;
}

if ([myString length] >= 55 && [myString length] <79){
version=4;
}

if ([myString length] > 80 && [myString length] <107){
version=5;
}

if ([myString length] >= 108 && [myString length] <135){
version=6;
}

if ([myString length] >= 136 && [myString length] <155){
version=9;
}

if ([myString length] >= 156 && [myString length] <193){
version=9;
}

return version;
}

Now there are no memory errors and you always get an image being output even for larger (100+ char) strings, however the image is often corrupt and not scannable by any QR decoder :(

Any help appretiated if I'm doing something wrong.