- This program is still under active development and in its early stage, consider that breaking changes and rewrites could occur before using it in a stable version
RPScanner is a wrapper around AVFoundation to use scanning capabilities of the iPhone Camera to detect Barcodes & QRCodes
- Barcode types:
- QRCode types:
Configure Scanner initialization and destruction
@IBOutlet var cameraPreview: UIView!
var scanner: RPScanner? = nil
// MARK: - Controller / Views initialization
override func viewDidLoad() {
super.viewDidLoad()
initScanner()
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
clearScanner()
}
func initScanner() {
scanner = RPScanner()
scanner?.viewForPreview = self.cameraPreview
scanner?.delegate = self
scanner?.useFrontCamera = false
if AVCaptureDevice.authorizationStatus(forMediaType: AVMediaTypeVideo) == AVAuthorizationStatus.authorized {
self.scanner?.start()
} else {
AVCaptureDevice.requestAccess(forMediaType: AVMediaTypeVideo, completionHandler: { (granted :Bool) -> Void in
if granted == true {
self.scanner?.start()
}
});
}
}
func clearScanner() {
scanner?.stop()
self.scanner = nil
}Implement RPScannerDelegate methods to handle scanned events
func scanCodeDetected(_ code: String, barcodeType: String) {
// do something
}
func scanCodeFailedWithError(_ error: NSError) {
// handle detection error
}RPFramework can be added to your project using CocoaPods by adding the following lines to your Podfile:
source 'https://github.com/RedP4nda/Specs'
pod 'RPScanner', '~> 0.9'Contributions are very welcome 👍😃.
Before submitting any pull request, please ensure you have run the included tests (if any) and they have passed. If you are including new functionality, please write test cases for it as well.
