GithubHelp home page GithubHelp logo

inottawa / mtbbarcodescanner Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mikebuss/mtbbarcodescanner

0.0 2.0 0.0 3 MB

A lightweight, easy-to-use barcode scanning library for iOS 7

License: MIT License

mtbbarcodescanner's Introduction

MTBBarcodeScanner

Version License Platform

A lightweight, easy-to-use barcode scanning library for iOS 7.

With this library you can:

  • Supply a custom UIView for displaying camera input
  • Read any number of barcodes before stopping
  • Read multiple codes on the screen at the same time (2D barcodes only)
  • Easily receive codes with a block, including the string value and position in the preview

See demo project for examples of capturing one code, multiple codes, or highlighting codes as valid or invalid in the live preview.


Sample Barcodes

Installation

MTBBarcodeScanner can be installed via CocoaPods by adding the following line to your Podfile:

pod "MTBBarcodeScanner"

If you'd prefer not to use CocoaPods, you can download these two files and add them to your project:

MTBBarcodeScanner.h

MTBBarcodeScanner.m

Usage

To import the library: #import "MTBBarcodeScanner.h"

Initialization

To initialize an instance of MTBBarcodeScanner:

scanner = [[MTBBarcodeScanner alloc] initWithPreviewView:self.previewView];

Where previewView is the UIView in which the camera input will be displayed.

If you only want to scan for certain MetaObjectTypes, you can initialize with the initWithMetadataObjectTypes:previewView: method:

s = [[MTBBarcodeScanner alloc] initWithMetadataObjectTypes:@[AVMetadataObjectTypeQRCode]
                                               previewView:self.previewView];

Scanning

To read the first code and stop scanning:

[self.scanner startScanningWithResultBlock:^(NSArray *codes) {
        AVMetadataMachineReadableCodeObject *code = [codes firstObject];
        NSLog(@"Found code: %@", code.stringValue);
        [self.scanner stopScanning];
    }];

If the camera is pointed at more than one 2-dimensional code, you can read all of them:

[self.scanner startScanningWithResultBlock:^(NSArray *codes) {
        for (AVMetadataMachineReadableCodeObject *code in codes) {
            NSLog(@"Found code: %@", code.stringValue);
        }
        [self.scanner stopScanning];
    }];

Note: This only applies to 2-dimensional barcodes as 1-dimensional barcodes can only be read one at a time. See relevant Apple document.

To continuously read and only output unique codes:

[self.scanner startScanningWithResultBlock:^(NSArray *codes) {
        for (AVMetadataMachineReadableCodeObject *code in codes) {
            if ([self.uniqueCodes indexOfObject:code.stringValue] == NSNotFound) {
                [self.uniqueCodes addObject:code.stringValue];
                NSLog(@"Found unique code: %@", code.stringValue);
            }
        }
    }];

Design Considerations

The primary goals of this library are:

  • Provide an easy-to-use interface for barcode scanning
  • Make as few assumptions about the scanning process as possible
    • Don't assume the user wants to scan one code at a time
    • Don't assume the camera input view should be a particular size
    • Don't assume the scanning process will have it's own view controller

Developer

Mike Buss

License

MTBBarcodeScanner is available under the MIT license. See the LICENSE file for more info.

mtbbarcodescanner's People

Contributors

ddmobiledev avatar laptobbe avatar mikebuss avatar philipdnichols avatar

Watchers

 avatar  avatar

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.