Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

🔎 A simple and beautiful barcode scanner.

License

NotificationsYou must be signed in to change notification settings

plangrid/BarcodeScanner

 
 

Repository files navigation

BarcodeScanner

CI StatusVersionSwiftCarthage CompatibleLicensePlatform

Description

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.

Table of Contents

BarcodeScanner Icon

Usage

Controller

To start capturing just instantiateBarcodeScannerViewController, set neededdelegates and present it:

letviewController=BarcodeScannerViewController()viewController.codeDelegate=selfviewController.errorDelegate=selfviewController.dismissalDelegate=selfpresent(viewController, animated:true, completion:nil)
BarcodeScanner scanning

You can also pushBarcodeScannerViewController to your navigation stack:

letviewController=BarcodeScannerViewController()viewController.codeDelegate=selfnavigationController?.pushViewController(viewController, animated:true)

Delegates

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)}}

Actions

When the code is capturedBarcodeScannerViewController switches to the processingmode:

BarcodeScanner loading

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:

  1. DismissBarcodeScannerViewController and show your results.
func scanner(_ controller:BarcodeScannerViewController, didCaptureCode code:String, type:String){ // Code processing controller.dismiss(animated:true, completion:nil)}
  1. 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):
BarcodeScanner error

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.}
  1. 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 theisOneTimeSearchproperty on yourBarcodeScannerViewController instance tofalse.

Customization

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)

Installation

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.

Author

Hyper Interaktiv AS,ios@hyper.no

Contributing

We would love you to contribute toBarcodeScanner, check theCONTRIBUTING file for more info.

License

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

Packages

No packages published

Languages

  • Swift98.3%
  • Ruby1.7%

[8]ページ先頭

©2009-2025 Movatter.jp