TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Apr 2016 |
SPMSupports SPM | ✗ |
Maintained by Sean McNeil.
To run the example project, clone the repo, and run pod install
from the Example directory first.
The bare minimum required to run this pod consists of the following in the UIViewController class you wish to handle scanning barcodes:
import SMCodeScanner
ScannerViewController
super.setupCaptureSession()
from one of your view configuration overrides (didLoad, willAppear, didAppear)self.delegate = self
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
}
}
You have two options that can be set:
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:
matchCode(lettersAllowed:allowCapitalLetters:numbersAllowed:)
matchCode(lettersAllowed:allowCapitalLetters:numbersAllowed:minLength:maxLength:)
matchCodeWithExpression(expression:)
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
}
public enum ScannerError : Int {
case ScannerErrorMinGreaterThanMaxLength = -100
case ScannerErrorMaxLengthLessThanOne = -101
case ScannerErrorInvalidObject = -102
}
SMCodeScanner is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "SMCodeScanner"
Sean McNeil, [email protected]
SMCodeScanner is available under the MIT license. See the LICENSE file for more info.