Latest 3.6.1
Homepage https://github.com/TheLevelUp/ZXingObjC
License Apache License 2.0
Platforms ios 8.0, osx 10.8, requires ARC

ZXingObjC is a full Objective-C port of ZXing ("Zebra Crossing"), a Java barcode image processing library. It is designed to be used on both iOS devices and in Mac applications.

The following barcodes are currently supported for both encoding and decoding:

  • UPC-A and UPC-E
  • EAN-8 and EAN-13
  • Code 39
  • Code 93
  • Code 128
  • ITF
  • Codabar
  • RSS-14 (all variants)
  • QR Code
  • Data Matrix
  • Maxicode
  • Aztec (‘beta’ quality)
  • PDF 417 (‘beta’ quality)

ZXingObjC currently has feature parity with ZXing version 3.3.3.

Requirements

ZXingObjC requires Xcode 8.3.3 and above, targeting either iOS 8.0 and above, or Mac OS X 10.8 Mountain Lion and above.

Usage

Encoding:

NSError *error = nil;
ZXMultiFormatWriter *writer = [ZXMultiFormatWriter writer];
ZXBitMatrix* result = [writer encode:@"A string to encode"
                              format:kBarcodeFormatQRCode
                               width:500
                              height:500
                               error:&error];
if (result) {
  CGImageRef image = CGImageRetain([[ZXImage imageWithMatrix:result] cgimage]);

  // This CGImageRef image can be placed in a UIImage, NSImage, or written to a file.

  CGImageRelease(image);
} else {
  NSString *errorMessage = [error localizedDescription];
}

Decoding:

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
                            hints:hints
                            error:&error];
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.
}

Installation

We highly recommend Carthage as module manager.

Carthage

ZXingObjC can be installed using Carthage. After installing Carthage just add ZXingObjC to your Cartfile:

github "TheLevelUp/ZXingObjC" ~> 3.6

CocoaPods

CocoaPods is a dependency manager for Swift and Objective-C Cocoa projects. After installing CocoaPods add ZXingObjC to your Podfile:

platform :ios, '8.0'
pod 'ZXingObjC', '~> 3.6.1'

Examples

ZXingObjC includes several example applications found in "examples" folder:

  • BarcodeScanner – An iOS application that captures video from the camera, scans for barcodes and displays results on screen.
  • BarcodeScannerSwift – An iOS application that captures video from the camera, scans for barcodes and displays results on screen, completely rewritten in Swift.

Kudos

  • cwalcott initial creator of this project
  • neacao for his unparalleled support lately

License

ZXingObjC is available under the Apache 2.0 license.

Latest podspec

{
    "name": "ZXingObjC",
    "version": "3.6.1",
    "summary": "An Objective-C Port of the ZXing barcode framework.",
    "homepage": "https://github.com/TheLevelUp/ZXingObjC",
    "authors": "ZXingObjC team",
    "license": {
        "type": "Apache License 2.0",
        "file": "COPYING"
    },
    "source": {
        "git": "https://github.com/TheLevelUp/ZXingObjC.git",
        "tag": "3.6.1"
    },
    "requires_arc": true,
    "xcconfig": {
        "OTHER_LDFLAGS": "-ObjC"
    },
    "platforms": {
        "ios": "8.0",
        "osx": "10.8"
    },
    "ios": {
        "frameworks": [
            "AVFoundation",
            "CoreGraphics",
            "CoreMedia",
            "CoreVideo",
            "ImageIO",
            "QuartzCore"
        ]
    },
    "osx": {
        "frameworks": [
            "AVFoundation",
            "CoreMedia",
            "QuartzCore"
        ]
    },
    "default_subspecs": "All",
    "subspecs": [
        {
            "name": "All",
            "source_files": "ZXingObjC/**/*.{h,m}"
        },
        {
            "name": "Core",
            "source_files": [
                "ZXingObjC/*.{h,m}",
                "ZXingObjC/client/*.{h,m}",
                "ZXingObjC/common/**/*.{h,m}",
                "ZXingObjC/core/**/*.{h,m}",
                "ZXingObjC/multi/**/*.{h,m}"
            ],
            "xcconfig": {
                "GCC_PREPROCESSOR_DEFINITIONS": "ZXINGOBJC_USE_SUBSPECS"
            }
        },
        {
            "name": "Aztec",
            "dependencies": {
                "ZXingObjC/Core": []
            },
            "source_files": "ZXingObjC/aztec/**/*.{h,m}",
            "xcconfig": {
                "GCC_PREPROCESSOR_DEFINITIONS": "ZXINGOBJC_USE_SUBSPECS ZXINGOBJC_AZTEC"
            }
        },
        {
            "name": "DataMatrix",
            "dependencies": {
                "ZXingObjC/Core": []
            },
            "source_files": "ZXingObjC/datamatrix/**/*.{h,m}",
            "xcconfig": {
                "GCC_PREPROCESSOR_DEFINITIONS": "ZXINGOBJC_USE_SUBSPECS ZXINGOBJC_DATAMATRIX"
            }
        },
        {
            "name": "MaxiCode",
            "dependencies": {
                "ZXingObjC/Core": []
            },
            "source_files": "ZXingObjC/maxicode/**/*.{h,m}",
            "xcconfig": {
                "GCC_PREPROCESSOR_DEFINITIONS": "ZXINGOBJC_USE_SUBSPECS ZXINGOBJC_MAXICODE"
            }
        },
        {
            "name": "OneD",
            "dependencies": {
                "ZXingObjC/Core": []
            },
            "source_files": [
                "ZXingObjC/oned/**/*.{h,m}",
                "ZXingObjC/client/result/**/*.{h,m}"
            ],
            "xcconfig": {
                "GCC_PREPROCESSOR_DEFINITIONS": "ZXINGOBJC_USE_SUBSPECS ZXINGOBJC_ONED"
            }
        },
        {
            "name": "PDF417",
            "dependencies": {
                "ZXingObjC/Core": []
            },
            "source_files": "ZXingObjC/pdf417/**/*.{h,m}",
            "xcconfig": {
                "GCC_PREPROCESSOR_DEFINITIONS": "ZXINGOBJC_USE_SUBSPECS ZXINGOBJC_PDF417"
            }
        },
        {
            "name": "QRCode",
            "dependencies": {
                "ZXingObjC/Core": []
            },
            "source_files": "ZXingObjC/qrcode/**/*.{h,m}",
            "xcconfig": {
                "GCC_PREPROCESSOR_DEFINITIONS": "ZXINGOBJC_USE_SUBSPECS ZXINGOBJC_QRCODE"
            }
        }
    ]
}

Pin It on Pinterest

Share This