SMCodeScanner 0.3.1

SMCodeScanner 0.3.1

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Apr 2016
SPMSupports SPM

Maintained by Sean McNeil.



SMCodeScanner

Usage

To run the example project, clone the repo, and run pod install from the Example directory first.

Instructions

The bare minimum required to run this pod consists of the following in the UIViewController class you wish to handle scanning barcodes:

  • import SMCodeScanner
  • Have the class inherit ScannerViewController
  • Call super.setupCaptureSession() from one of your view configuration overrides (didLoad, willAppear, didAppear)
  • After the setupCaptureSession() call, add the following self.delegate = self
  • Then add super.startSession()

Next, you will need to conform to the delegate methods that allow you to get the final barcode value, or an error message:

extension YOUR_VIEWCONTROLLERS_CLASS_NAME: ScannerDelegate {

    func scanner(scanner: ScannerViewController, barcode: String) {
        // Handle barcode here
    }

    func scanner(scanner: ScannerViewController, error: NSError) {
        // Handle errors here
    }
}

Options

You have two options that can be set:

  • What kind of barcode, or barcodes, to accept. The default value is QR
  • What values are acceptable from the barcode. The default value is all

You set the barcode value in the setupCaptureSession method by providing a type from the Barcode enum. These values are available below.

You set the acceptable values with the match functions. There are three options:

  • If you do not care about length and only character type, use: matchCode(lettersAllowed:allowCapitalLetters:numbersAllowed:)
  • If you need a specific length, or range of values, and certain character types, use: matchCode(lettersAllowed:allowCapitalLetters:numbersAllowed:minLength:maxLength:)
  • If neither of these is sufficient, you can provide your own regex expression with: matchCodeWithExpression(expression:)

Barcode type enum

public enum Barcode : String {
case TypeUPCE
case Type39
case Type39Mod43
case TypeEAN13
case TypeEAN8
case Type93
case Type128
case TypePDF417
case TypeQR
case TypeAztec
case TypeInterleaved
case TypeITF14
case TypeDataMatrix
}

Error code enum

public enum ScannerError : Int {
case ScannerErrorMinGreaterThanMaxLength = -100
case ScannerErrorMaxLengthLessThanOne = -101
case ScannerErrorInvalidObject = -102
}

Installation

SMCodeScanner is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "SMCodeScanner"

Author

Sean McNeil, [email protected]

License

SMCodeScanner is available under the MIT license. See the LICENSE file for more info.