BarcodeScanner Documentation
Introduction
Welcome to the documentation for BarcodeScanner! This guide provides detailed information on how to use the BarcodeScanner library for iOS development. Whether you are a beginner or an experienced developer, this documentation will help you integrate barcode scanning functionality into your iOS applications.
Getting Started
Installation
To install BarcodeScanner, follow these steps:
- Open your Xcode project
- Go to “File” > “Swift Packages” > “Add Package Dependency”
- Enter the repository URL: https://github.com/mw99/BarcodeScanner
- Choose the latest version
- Click “Next” and then “Finish”
Integrating BarcodeScanner
To integrate BarcodeScanner into your project, follow these steps:
- Import the BarcodeScanner module into your Swift file:
- Create an instance of the `BarcodeScannerViewController` class
- Set the delegate to receive scanning results
- Present the view controller
// Swift
import BarcodeScanner
Usage Example
Here’s an example of how to implement BarcodeScanner in your application:
// Swift
import UIKit
import BarcodeScanner
class ViewController: UIViewController, BarcodeScannerCodeDelegate {
override func viewDidLoad() {
super.viewDidLoad()
}
func scanBarcode() {
let barcodeScanner = BarcodeScannerViewController()
barcodeScanner.codeDelegate = self
present(barcodeScanner, animated: true, completion: nil)
}
func barcodeScanner(_ controller: BarcodeScannerViewController, didCaptureCode code: String, type: String) {
// Handle barcode scanning results
print("Scanned code: \(code)")
dismiss(animated: true, completion: nil)
}
}
API Reference
BarcodeScannerViewController
The `BarcodeScannerViewController` class provides the main interface for scanning barcodes. It inherits from `UIViewController`.
Properties
codeDelegate
: The delegate object to receive barcode scanning results.torchTintColor
: The color of the torch button. Accepts `UIColor`.cancelButtonColor
: The color of the cancel button. Accepts `UIColor`.
Methods
reset
: Clears any previously captured codes and resets the scanner.
Delegate Methods
barcodeScanner(_:didCaptureCode:type:)
: Called when a barcode is successfully captured. Returns the captured code and its type.barcodeScanner(_:didReceiveError:)
: Called when an error occurs during scanning. Returns the error object.barcodeScannerDidDismiss(_:)
: Called when the scanner is dismissed by the user.
Additional Resources
For more information on the BarcodeScanner library, check out the following resources: