Giter Site home page Giter Site logo

mercari / qrscanner Goto Github PK

View Code? Open in Web Editor NEW
315.0 12.0 74.0 11.65 MB

A simple QR Code scanner framework for iOS. Provides a similar scan effect to ios13+.

License: MIT License

Ruby 2.32% Objective-C 1.81% Swift 95.87%
qrscanner qrcode qrcode-reader qrcode-scanner qr swift ios

qrscanner's Introduction

QRScanner

A simple QR Code scanner framework for iOS. Provides a similar scan effect to ios13+. Written in Swift.

iOS 13.0+ Use QRScanner in iOS 10.0+

"QR Code" is a registered trademark of DENSO WAVE INCORPORATED

Feature

  • Similar to iOS 13.0+ design
  • Simple usage Sample
  • Support from iOS 10.0+

Development Requirements

  • iOS 11.0+
  • Swift: 5.7.1
  • Xcode Version: 14.1

Installation

QRScanner supports multiple methods for installing the library in a project.

Installation with CocoaPods

  • To integrate QRScanner into your Xcode project using CocoaPods, specify it in your Podfile
  platform :ios, '11.0'
  pod 'MercariQRScanner'
  • Run command
  pod install
  • Write Import statement on your source file
  import MercariQRScanner

Installation with Swift Package Manager

Once you have your Swift package set up, adding QRScanner as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
    .package(url: "https://github.com/mercari/QRScanner.git", .upToNextMajor(from: "1.9.0"))
]
  • Write Import statement on your source file
import QRScanner

Installation with Carthage

  • To integrate QRScanner, add the following to your Cartfile.
github "mercari/QRScanner"
  • Write Import statement on your source file
import QRScanner

Usage

See QRScannerSample

Add Privacy - Camera Usage Description to Info.plist file

The Basis Of Usage

import QRScanner // If use the Pod way, please import MercariQRScanner
import AVFoundation

final class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        setupQRScanner()
    }

    private func setupQRScanner() {
        switch AVCaptureDevice.authorizationStatus(for: .video) {
        case .authorized:
            setupQRScannerView()
        case .notDetermined:
            AVCaptureDevice.requestAccess(for: .video) { [weak self] granted in
                if granted {
                    DispatchQueue.main.async { [weak self] in
                        self?.setupQRScannerView()
                    }
                }
            }
        default:
            showAlert()
        }
    }

    private func setupQRScannerView() {
        let qrScannerView = QRScannerView(frame: view.bounds)
        view.addSubview(qrScannerView)
        qrScannerView.configure(delegate: self, input: .init(isBlurEffectEnabled: true))
        qrScannerView.startRunning()
    }

    private func showAlert() {
        DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { [weak self] in
            let alert = UIAlertController(title: "Error", message: "Camera is required to use in this application", preferredStyle: .alert)
            alert.addAction(.init(title: "OK", style: .default))
            self?.present(alert, animated: true)
        }
    }
}

extension ViewController: QRScannerViewDelegate {
    func qrScannerView(_ qrScannerView: QRScannerView, didFailure error: QRScannerError) {
        print(error)
    }

    func qrScannerView(_ qrScannerView: QRScannerView, didSuccess code: String) {
        print(code)
    }
}

Customization

Source Code Way

override func viewDidLoad() {
        super.viewDidLoad()

        let qrScannerView = QRScannerView(frame: view.bounds)

        // Customize focusImage, focusImagePadding, animationDuration
        qrScannerView.focusImage = UIImage(named: "scan_qr_focus")
        qrScannerView.focusImagePadding = 8.0
        qrScannerView.animationDuration = 0.5

        qrScannerView.configure(delegate: self)
        view.addSubview(qrScannerView)
        qrScannerView.startRunning()
}

Interface Builder Way

Setup Custom Class Customize

Add FlashButton

FlashButtonSample

final class ViewController: UIViewController {

    ...

    @IBOutlet var flashButton: FlashButton!

    @IBAction func tapFlashButton(_ sender: UIButton) {
        qrScannerView.setTorchActive(isOn: !sender.isSelected)
    }
}

extension ViewController: QRScannerViewDelegate {

    ...

    func qrScannerView(_ qrScannerView: QRScannerView, didChangeTorchActive isOn: Bool) {
        flashButton.isSelected = isOn
    }
}

Add Blur Effect

Source Code Way

     qrScannerView.configure(delegate: self, input: .init(isBlurEffectEnabled: true))

Interface Builder Way

Customize

Committers

Contribution

Please read the CLA carefully before submitting your contribution to Mercari. Under any circumstances, by submitting your contribution, you are deemed to accept and agree to be bound by the terms and conditions of the CLA.

https://www.mercari.com/cla/

License

Copyright 2019 Mercari, Inc.

Licensed under the MIT License.

qrscanner's People

Contributors

art22m avatar daichiro avatar daisuke-t-jp avatar hitsubunnu avatar looking4cache avatar woxtu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

qrscanner's Issues

Add tests

  • Write unit tests
  • Write snapshot test (if needed)
  • Set CI
    • Can we use GitHub actions?

Not handling authorization properly

When I run the app first time, I get didFailure twice with error:

unauthorized(__C.AVAuthorizationStatus)
unauthorized(__C.AVAuthorizationStatus)

and at the same time authorization alert shows up. When I tap "Deny" didFailure is not triggered anymore. It should not throw this errors before user makes a decision.

Erro when add by Swift Package Manager

i`m try install using SPM, but receive this error:

because no versions of QRScanner match the requirement XXX..<XXX and root depends on QRScanner XXX..<XXX, version solving failed.

What version a have to define?

Add blur effect for customization

eg.

    let blurEffect = UIBlurEffect(style: .dark)
    let blurEffectView = UIVisualEffectView(effect: blurEffect)
    blurEffectView.frame = self.view.bounds
    blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]

    view.addSubview(blurEffectView)

New class `QRScannerController` added

Hi everybody,

I have created a class QRScannerController , it can use camera and Photo library. it's very easy-to-use, would you hope
me merge the code to this repo?

https://github.com/ShadowsocksR-Live/QRScanner

import UIKit
import QRScanner

final class ViewController: UIViewController {

    @IBOutlet weak var resultLabel: UILabel!
    
    @IBAction func readQrCode(_ sender: Any) {
        let ctrl = QRScannerController()
        ctrl.success = { code in
            self.resultLabel.text = code
            self.dismiss(animated: true, completion: nil)
        }
        self.present(ctrl, animated: true, completion: nil)
    }
}

photo_2022-04-20_18-53-33

Does this use the native service in iOS 13+?

The description of this package says that it emulates the native QR scanning support of iOS 13 on older OS versions. Does that mean that if you are running iOS 13 or later, it acts as a simple wrapper for the built-in service and does not handle the scanning itself?

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.