- Notifications
You must be signed in to change notification settings - Fork0
🔎 A simple and beautiful barcode scanner.
License
plangrid/BarcodeScanner
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
BarcodeScanner is a simple and beautiful wrapper around the camera withbarcode capturing functionality and a great user experience.
- Barcode scanning.
- State modes: scanning, processing, unauthorized, not found.
- Handling of camera authorization status.
- Animated focus view and custom loading indicator.
- Torch mode switch.
- Customizable colors, informational and error messages.
- No external dependencies.
- Demo project.
To start capturing just instantiateBarcodeScannerViewController
, set neededdelegates and present it:
letviewController=BarcodeScannerViewController()viewController.codeDelegate=selfviewController.errorDelegate=selfviewController.dismissalDelegate=selfpresent(viewController, animated:true, completion:nil)
You can also pushBarcodeScannerViewController
to your navigation stack:
letviewController=BarcodeScannerViewController()viewController.codeDelegate=selfnavigationController?.pushViewController(viewController, animated:true)
Code delegate
UseBarcodeScannerCodeDelegate
when you want to get the captured code back.
extensionViewController:BarcodeScannerCodeDelegate{func scanner(_ controller:BarcodeScannerViewController, didCaptureCode code:String, type:String){print(code) controller.reset()}}
Error delegate
UseBarcodeScannerErrorDelegate
when you want to handle session errors.
extensionViewController:BarcodeScannerErrorDelegate{func scanner(_ controller:BarcodeScannerViewController, didReceiveError error:Error){print(error)}}
Dismissal delegate
UseBarcodeScannerDismissalDelegate
to handle "Close button" tap.Please note thatBarcodeScannerViewController
doesn't dismiss itself ifit was presented initially.
extensionViewController:BarcodeScannerDismissalDelegate{func scannerDidDismiss(_ controller:BarcodeScannerViewController){ controller.dismiss(animated:true, completion:nil)}}
When the code is capturedBarcodeScannerViewController
switches to the processingmode:
While the user sees a nice loading animation you can perform somebackground task, for example make a network request to fetch product info basedon the code. When the task is done you have 3 options to proceed:
- Dismiss
BarcodeScannerViewController
and show your results.
func scanner(_ controller:BarcodeScannerViewController, didCaptureCode code:String, type:String){ // Code processing controller.dismiss(animated:true, completion:nil)}
- Show an error message and switch back to the scanning mode (for example,when there is no product found with a given barcode in your database):
func scanner(_ controller:BarcodeScannerViewController, didCaptureCode code:String, type:String){ // Code processing controller.resetWithError(message:"Error message") // If message is not provided the default message will be used instead.}
- Reset the controller to the scanning mode (with or without animation):
func scanner(_ controller:BarcodeScannerViewController, didCaptureCode code:String, type:String){ // Code processing controller.reset(animated:true)}
If you want to do continuous barcode scanning just set theisOneTimeSearch
property on yourBarcodeScannerViewController
instance tofalse
.
We styledBarcodeScanner to make it look nice, but you can always use publicproperties or inheritance to customize its appearance.
Header
letviewController=BarcodeScannerViewController()viewController.headerViewController.titleLabel.text="Scan barcode"viewController.headerViewController.closeButton.tintColor=.red
Please note thatHeaderViewController
is visible only whenBarcodeScannerViewController
is being presented.
Footer and messages
letviewController=BarcodeScannerViewController()viewController.messageViewController.regularTintColor=.blackviewController.messageViewController.errorTintColor=.redviewController.messageViewController.textLabel.textColor=.black
Camera
letviewController=BarcodeScannerViewController()// Change focus view styleviewController.cameraViewController.barCodeFocusViewType=.animated// Show camera position buttonviewController.cameraViewController.showsCameraButton=true// Set settings button textlettitle=NSAttributedString( string:"Settings", attributes:[.font:UIFont.boldSystemFont(ofSize:17),.foregroundColor:UIColor.white])viewController.cameraViewController.settingButton.setAttributedTitle(title, for:UIControlState())
Metadata
// Add extra metadata object typeletviewController=BarcodeScannerViewController()viewController.metadata.append(AVMetadataObject.ObjectType.qr)
BarcodeScanner is available throughCocoaPods. To installit, simply add the following line to your Podfile:
pod'BarcodeScanner'
Don't forget to set aPrivacy - Camera Usage Description
in your Info.plist file, else the app will crash with a SIGBART.
In order to quickly try the demo project of aBarcodeScanner just runpod try BarcodeScanner
in your terminal.
BarcodeScanner is also available throughCarthage.To install just write into your Cartfile:
github"hyperoslo/BarcodeScanner"
To installBarcodeScanner manually just download and dropSources
andImages
folders in your project.
Hyper Interaktiv AS,ios@hyper.no
We would love you to contribute toBarcodeScanner, check theCONTRIBUTING file for more info.
BarcodeScanner is available under the MIT license. See theLICENSE file for more info.
About
🔎 A simple and beautiful barcode scanner.
Resources
License
Stars
Watchers
Forks
Packages0
Languages
- Swift98.3%
- Ruby1.7%