Giter VIP home page Giter VIP logo

qrbot's Introduction

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)
    1. 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.

    1. 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.

    1. 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 ❤️ in India.

qrbot's People

Contributors

hardiiik avatar hardik-trivedii avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

carabina

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.