[BREAKGLASS] Append-only mirror of github.com/signalapp/ZXingObjC
Go to file
2018-11-30 14:35:39 +01:00
examples Reindent ViewController 2018-10-09 17:06:56 +07:00
ZXingObjC Merge pull request #458 from TheLevelUp/port-zxing-1103 2018-11-30 14:34:23 +01:00
ZXingObjC.xcodeproj Bumped version to 3.6.2 (xcodeproj) 2018-11-30 14:35:20 +01:00
ZXingObjCTests Ported 'fix code93 extended character decoder' 2018-11-30 14:30:59 +01:00
.gitattributes Separate unit and blackbox tests into different targets 2014-01-28 17:22:46 -05:00
.gitignore Separate unit and blackbox tests into different targets 2014-01-28 17:22:46 -05:00
AUTHORS Updated ZXing AUTHORS file 2015-03-24 17:11:51 -04:00
AUTHORS-ZXingObjC Updated ZXingObjC AUTHORS 2015-03-24 09:40:10 -04:00
COPYING Add licensing info 2012-03-16 10:40:48 -04:00
ios-Info.plist Update project for Xcode 7 2015-10-08 11:13:09 -04:00
ios-Prefix.pch ZXingObjC now works as a framework, and has a framework header 2012-12-01 22:39:41 -05:00
mac-Info.plist Add Info.plist to Mac Framework 2017-02-19 20:43:48 +11:00
NOTICE Ported "PDF417 encoder, modified from Barcode4J" 2012-05-26 18:06:39 -04:00
osx-Prefix.pch Added Mac OS X targets, and included client ObjC classes from ZXing 2012-04-24 16:23:47 -04:00
README.md Changed version in README 2018-11-01 10:50:08 +01:00
ZXingObjC.podspec Bumped version to 3.6.2 (podspec) 2018-11-30 14:35:39 +01:00

ZXingObjC

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.