A small and configurable Code Scanner for iOS
Requirements .iOS(.v10)
.package(url: "https://github.com/DungeonDev78/AMCodeScanner.git", .upToNextMajor(from: "1.0.0"))
Import AMCodeScanner package to your controller
import AMCodeScanner
Add the Privacy - Camera Usage Description in your Info.plist
In your ViewController (or in its Storyboard) add two UIView, one for the camera preview and a second one, that is optional, for the area of interest where you should search for the code to scan.
Add the scanner property:
var scanner: AMCodeScanner?
In viewWillAppear init the code reader:
scanner = AMCodeScanner(
cameraView: cameraView,
areaOfInterest: focusView,
maskColor: #colorLiteral(red: 0, green: 0, blue: 0, alpha: 0.5),
aoiCornerRadius: 10,
typesToScan: [.qr, .code128, .dataMatrix],
completion: { result in
switch result {
case .success(let code):
print("Code scaned: \(code)")
case .failure(let error):
print(error)
}
})
The completion handler will handle the result of the reading.
If you need to stop or restart your reader, use the functions:
func stopScanning()
func startScanning()
import UIKit
import AMCodeScanner
class ViewController: UIViewController {
// MARK: - Properties
@IBOutlet weak private var cameraView: UIView!
@IBOutlet weak private var focusView: UIView!
private var scanner: AMCodeScanner?
// MARK: - Lifecycle
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
scanner = AMCodeScanner(
cameraView: cameraView,
areaOfInterest: focusView,
maskColor: #colorLiteral(red: 0, green: 0, blue: 0, alpha: 0.5),
aoiCornerRadius: 10,
typesToScan: [.qr, .code128, .dataMatrix],
completion: { result in
switch result {
case .success(let code):
print("Code scanned: \(code)")
case .failure(let error):
print(error)
}
})
}
}
In the init function, if desired, you can avoid to pass:
This project is licensed under the MIT License
link |
Stars: 1 |
Last commit: 3 years ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics