Get Updates By E-mail 

Article Written By:
Johann Dowa

Fully Objective-C Port Of Open Source Barcode Scanner/Creator ZXing


I’ve mentioned an open source app called Barcode scanner that provides an example showing how to use the C++ port of ZXing on the iOS platform.

Recently I received a tip about a Objective-C port of Zxing called ZXingObjc.

ZXingObjc provides a full port of ZXing to Objective-C so all your barcode scanning, and barcode creation can be done completely with Objective-C without the hassle of linking up to and using the C++ ZXing port.

Here’s an example from the readme shows decoding done using Objective-C:

CGImageRef imageToDecode;  // Given a CGImage in which we are looking for barcodes

ZXLuminanceSource* source = [[[ZXCGImageLuminanceSource alloc] initWithCGImage:imageToDecode] autorelease];
ZXBinaryBitmap* bitmap = [ZXBinaryBitmap binaryBitmapWithBinarizer:[ZXHybridBinarizer binarizerWithSource:source]];

NSError* error = nil;

// There are a number of hints we can give to the reader, including
// possible formats, allowed lengths, and the string encoding.
ZXDecodeHints* hints = [ZXDecodeHints hints];

ZXMultiFormatReader* reader = [ZXMultiFormatReader reader];
ZXResult* result = [reader decode:bitmap
if (result) {
  // The coded result as a string. The raw data can be accessed with
  // result.rawBytes and result.length.
  NSString* contents = result.text;

  // The barcode format, such as a QR code or UPC-A
  ZXBarcodeFormat format = result.barcodeFormat;
} else {
  // Use error to determine why we didn't get a result, such as a barcode
  // not being found, an invalid checksum, or a format inconsistency.

You can find ZXingObjc on Github here.

Examples are included for creating and scanning bar codes and QR codes.

Thanks to Chris for the submission.


Submit A Resource

Have you created a useful tutorial, library or tool for iOS development that you would like to get in front of our 300,000+ monthly page views from iOS developers?

You can submit the url here.

The resources we feel will appeal to our readers the most will be posted on the front page.