Latest 0.2.2
Homepage https://github.com/hardiiik/QRBot
License MIT
Platforms ios 8.0
Frameworks UIKit, AVFoundation
Authors

QRBot

A QR Code Scanning and Generating library for iOS 8+, written in Swift 4.

CI Status
Version
License
Platform

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:

  • Steps for scanning QR Code:
  1. You need to give permission to access Camera in Info.plist.

Info.plist permission

  1. Make QRCodeScannerViewController superclass of your ViewController class.
 class ViewController: QRCodeScannerViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
    }
 }
  1. 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
    }
 }
  1. Set scannerDelegate property of your ViewController to self.
 class ViewController: QRCodeScannerViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        scannerDelegate = self
    }
 }
  1. All set. Now implement your tasks in delegate method.
  • Steps for generating QR Code from your own data:
  1. Import QRBot in your ViewController.
 import QRBot
  1. Call generate() method of QRCode class as shown below:
 import UIKit
 import QRBot
 class YourViewController: UIViewController{
    ovveride func viewDidLoad(){
        super.viewDidLoad()
        QRCode.generate(from: yourStringData,completion: { (image,error) in
            if error == nil{
                if let qrCodeImage = image{
                    // Set qrCodeImage to your ImageView
                    self.imageView.image = qrCodeImage // For example
                }
            }
        })
    }
 }
  1. Below the list of supported methods are given. Their usages are as same as shown above.

    1) Simple Black & White QR Code from your String data

    QRCode.generate(from data: String, completion: @escaping (UIImage?,Error?) -> Void)

    2) Simple Black & White QRCode from your String data, with Image format you wish

    QRCode.generate(from data: String, imageFormat format: QRCodeImageFormat,completion: @escaping (UIImage?,Error?) -> Void)

    Here, QRCodeImageFormat is enum having values like .png, .jpg, .jpeg, .gif.

    3) QRCode with different Pattern Colour and Background Colour

    QRCode.generate(from data: String, patternColor color: QRCodeColor,backgroundColor bgcolor: QRCodeColor, completion: @escaping (UIImage?,Error?) -> Void)

    Here, QRCodeColor is enum, having all colours from Apple Colour Pallete.

    4) QRCode with different Pattern Colour and Background Colour, with Image format you wish

    QRCode.generate(from data: String, patternColor color: QRCodeColor,backgroundColor bgcolor: QRCodeColor, imageFormat format: QRCodeImageFormat, completion: @escaping (UIImage?,Error?) -> Void)

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]

Made with :heart: in India.

Latest podspec

{
    "name": "QRBot",
    "version": "0.2.2",
    "summary": "QRBot, a QR Code Scanning and Generating library for iOS 9+, written in Swift 4.",
    "description": "'QRBot is a library to simplify QR code scanning and generating new QR code tasks. You just need to make our class as super class of your ViewController and conform one protocol to scan QR Code using your app. And for generating new Code from your data, you need to call one method. We made these complex tasks that easy for you. :)'",
    "homepage": "https://github.com/hardiiik/QRBot",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Hardik Trivedi": "[email protected]"
    },
    "source": {
        "git": "https://github.com/hardiiik/QRBot.git",
        "tag": "0.2.2"
    },
    "social_media_url": "https://twitter.com/@HardikTrivedi_D",
    "platforms": {
        "ios": "8.0"
    },
    "swift_version": "4.0",
    "source_files": [
        "QRCodeScan/*.{swift}",
        "QRCodeGeneration/*.swift"
    ],
    "frameworks": [
        "UIKit",
        "AVFoundation"
    ]
}

Pin It on Pinterest

Share This