mcsheffrey
mcsheffrey

Reputation: 548

iOS generated QR code not recognized on other platforms

I am generating a QR code image using the CIQRCodeGenerator filter available from CIFilter. The image is generated fine and when it's displayed I can read the image using AVCaptureSession. However, when I try to scan the QR code using a different platform (Android, BlackBerry, iOS 6) then it doesn't recognize the image. According to Apple's documentation the generated image is compliant with the ISO/IEC 18004:2006 standard. Is the problem that I need something that is compliant with ISO 18004:2000?

Here is the code I'm using to generate the image:

NSData *stringData = [stringToEncode dataUsingEncoding:NSISOLatin1StringEncoding];

CIFilter *qrFilter = [CIFilter filterWithName:@"CIQRCodeGenerator"];

[qrFilter setValue:stringData forKey:@"inputMessage"];
[qrFilter setValue:@"M" forKey:@"inputCorrectionLevel"];

CIImage *qrImage = qrFilter.outputImage;

return [UIImage squareUIImageFromCIImage:qrImage withSize:size];

Here is a sample QR code:

sample QR code

Does anybody know if there is a way to generate a more universally recognized QR code image using CIFilter? I'd really prefer not to go back to using ZXing.

Thank you!

Upvotes: 0

Views: 3693

Answers (2)

Chris
Chris

Reputation: 7310

I'm not sure if the slight change makes a difference, but here's a snippet from my recent project that generates a QR code that is scanned from an iPad camera successfully in under a second:

 CIFilter *filter = [CIFilter filterWithName:@"CIQRCodeGenerator"];

[filter setDefaults];

NSData *data = [accountNumber dataUsingEncoding:NSUTF8StringEncoding];
[filter setValue:data forKey:@"inputMessage"];

CIImage *outputImage = [filter outputImage];

CIContext *context = [CIContext contextWithOptions:nil];
CGImageRef cgImage = [context createCGImage:outputImage
                                   fromRect:[outputImage extent]];

UIImage *barcode = [UIImage imageWithCGImage:cgImage
                                     scale:1.
                               orientation:UIImageOrientationUp];

// EDIT: 
CFRelease(cgImage);

Upvotes: 4

Aaron Brager
Aaron Brager

Reputation: 66302

You are using the ISO-8859-1 character set, but different QR code readers assume different things about the character encoding depending on which version of the standard they're following. UTF-8 seems to be more common than ISO-8859-1.

Upvotes: 1

Related Questions