QRBot
Requirements
iOS 8+
Installation
QRBot is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'QRBot'
Usage
Follow the steps to use QRBot:
- You need to give permission to access Camera in
Info.plist
.
- Make
QRCodeScannerViewController
superclass of your ViewController class.
class ViewController: QRCodeScannerViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
}
- Conform/ Implement
QRCodeScannerDelegate
protocol and implement its method to perform your tasks.
class ViewController: QRCodeScannerViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
}
extension ViewController: QRCodeScannerDelegate{
func scanner(_ connection: AVCaptureConnection, didOutput data: String) {
print("DemoApp : Data from QR Code - \(data)")
// Perform your actions here with data from QRCode
}
}
( If AVCaptureConnection
may show any error, just import AVFoundation
in your ViewController. )
import UIKit
import AVFoundation
import QRBot
class ViewController: QRCodeScannerViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
}
extension ViewController: QRCodeScannerDelegate{
func scanner(_ connection: AVCaptureConnection, didOutput data: String) {
print("DemoApp : Data from QR Code - \(data)")
// Perform your actions here with data from QRCode
}
}
- Set
scannerDelegate
property of your ViewController toself
.
class ViewController: QRCodeScannerViewController {
override func viewDidLoad() {
super.viewDidLoad()
scannerDelegate = self
}
}
- All set. Now implement your tasks in delegate method.
Example
Take a look at Example Project for more clarity. To run the example project, clone the repo, and run pod install
from the Example directory first.
Author
Hardik Trivedi, [email protected]
License
QRBot is available under the MIT license. See the LICENSE file for more info.