ProductPromotion
Logo

Swift

made by https://0x3d.site

GitHub - hyperoslo/BarcodeScanner: :mag_right: A simple and beautiful barcode scanner.
:mag_right: A simple and beautiful barcode scanner. - hyperoslo/BarcodeScanner
Visit Site

GitHub - hyperoslo/BarcodeScanner: :mag_right: A simple and beautiful barcode scanner.

GitHub - hyperoslo/BarcodeScanner: :mag_right: A simple and beautiful barcode scanner.

BarcodeScanner

CI Status Version Swift Carthage Compatible License Platform

Description

BarcodeScanner is a simple and beautiful wrapper around the camera with barcode 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

Usage

Controller

To start capturing just instantiate BarcodeScannerViewController, set needed delegates and present it:

let viewController = BarcodeScannerViewController()
viewController.codeDelegate = self
viewController.errorDelegate = self
viewController.dismissalDelegate = self

present(viewController, animated: true, completion: nil)

You can also push BarcodeScannerViewController to your navigation stack:

let viewController = BarcodeScannerViewController()
viewController.codeDelegate = self

navigationController?.pushViewController(viewController, animated: true)

Delegates

Code delegate

Use BarcodeScannerCodeDelegate when you want to get the captured code back.

extension ViewController: BarcodeScannerCodeDelegate {
  func scanner(_ controller: BarcodeScannerViewController, didCaptureCode code: String, type: String) {
    print(code)
    controller.reset()
  }
}

Error delegate

Use BarcodeScannerErrorDelegate when you want to handle session errors.

extension ViewController: BarcodeScannerErrorDelegate {
  func scanner(_ controller: BarcodeScannerViewController, didReceiveError error: Error) {
    print(error)
  }
}

Dismissal delegate

Use BarcodeScannerDismissalDelegate to handle "Close button" tap. Please note that BarcodeScannerViewController doesn't dismiss itself if it was presented initially.

extension ViewController: BarcodeScannerDismissalDelegate {
  func scannerDidDismiss(_ controller: BarcodeScannerViewController) {
    controller.dismiss(animated: true, completion: nil)
  }
}

Actions

When the code is captured BarcodeScannerViewController switches to the processing mode:

While the user sees a nice loading animation you can perform some background task, for example make a network request to fetch product info based on the code. When the task is done you have 3 options to proceed:

  1. Dismiss BarcodeScannerViewController 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):
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 the isOneTimeSearch property on your BarcodeScannerViewController instance to false.

Customization

We styled BarcodeScanner to make it look nice, but you can always use public properties or inheritance to customize its appearance.

Header

let viewController = BarcodeScannerViewController()
viewController.headerViewController.titleLabel.text = "Scan barcode"
viewController.headerViewController.closeButton.tintColor = .red

Please note that HeaderViewController is visible only when BarcodeScannerViewController is being presented.

Footer and messages

let viewController = BarcodeScannerViewController()
viewController.messageViewController.regularTintColor = .black
viewController.messageViewController.errorTintColor = .red
viewController.messageViewController.textLabel.textColor = .black

Camera

let viewController = BarcodeScannerViewController()
// Change focus view style
viewController.cameraViewController.barCodeFocusViewType = .animated
// Show camera position button
viewController.cameraViewController.showsCameraButton = true
// Set the initial camera position
viewController.cameraViewController.initialCameraPosition = .front // Default is .back
// Set settings button text
let title = NSAttributedString(
  string: "Settings",
  attributes: [.font: UIFont.boldSystemFont(ofSize: 17), .foregroundColor : UIColor.white]
)
viewController.cameraViewController.settingButton.setAttributedTitle(title, for: UIControlState())

Metadata

// Add extra metadata object type
let viewController = BarcodeScannerViewController()
viewController.metadata.append(AVMetadataObject.ObjectType.qr)

Installation

BarcodeScanner is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'BarcodeScanner'

Don't forget to set a Privacy - 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 a BarcodeScanner just run pod try BarcodeScanner in your terminal.

BarcodeScanner is also available through Carthage. To install just write into your Cartfile:

github "hyperoslo/BarcodeScanner"

To install BarcodeScanner manually just download and drop Sources and Images folders in your project.

Author

Hyper Interaktiv AS, [email protected]

Contributing

We would love you to contribute to BarcodeScanner, check the CONTRIBUTING file for more info.

License

BarcodeScanner is available under the MIT license. See the LICENSE file for more info.

More Resources
to explore the angular.

mail [email protected] to add your project or resources here ๐Ÿ”ฅ.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here ๐Ÿ”.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory