Latest 0.3.1
Homepage https://github.com/seanmcneil/SMCodeScanner
License MIT
Platforms ios 8.1, requires ARC
Authors

Version
License
Platform

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.

Latest podspec

{
    "name": "SMCodeScanner",
    "version": "0.3.1",
    "summary": "A drop in pod that allows you to specify the barcode you want",
    "description": "This allows you to specify both the type(s) of barcode(s) you want to accept, as well as specify criteria around what they can contain. Specifying type is done through the Barcode enum, which aligns with the supported types AVFoundation has. You can specify acceptable barcode values by either providing parameters to two prebuilt methods, or you can provide your own custom regex expression for more complex values. This pod is also able to determine if it is being run against a simulator, and will avoid launching the scanner if it is.",
    "homepage": "https://github.com/seanmcneil/SMCodeScanner",
    "license": "MIT",
    "authors": {
        "Sean McNeil": "[email protected]"
    },
    "source": {
        "git": "https://github.com/seanmcneil/SMCodeScanner.git",
        "tag": "0.3.1"
    },
    "social_media_url": "https://twitter.com/sean_mcneil",
    "platforms": {
        "ios": "8.1"
    },
    "requires_arc": true,
    "source_files": "Pod/Classes/**/*",
    "resource_bundles": {
        "SMCodeScanner": [
            "Pod/Assets/*.png"
        ]
    }
}

Pin It on Pinterest

Share This