GithubHelp home page GithubHelp logo

hathway / credit-card-scanner Goto Github PK

View Code? Open in Web Editor NEW

This project forked from yhkaplan/credit-card-scanner

0.0 1.0 0.0 871 KB

An iOS library using the Vision API to read credit card information

License: Other

Swift 84.03% Makefile 0.79% Shell 12.31% Ruby 2.88%

credit-card-scanner's Introduction

๐Ÿ’ณ CreditCardScanner

CreditCardScanner is a library for scanning credit cards to make adding payment information to user accounts easy. It uses Apple's Vision API for secure, on-device machine learning to read the following info from a credit card: number, name, and expiration date.

Example of CreditCardScanner running

Installing

Requirements

  • iOS 13.0+ (due to Vision API having first appeared in iOS 13.0)
    • Even if your minimum deployment target is iOS 12 or lower, you can make this an iOS 13.0+ only feature using canImport and @available
#if canImport(CreditCardScanner)
import CreditCardScanner
#endif

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

        if #available(iOS 13, *) {
            let creditCardScannerViewController = CreditCardScannerViewController(delegate: self)
            present(creditCardScannerViewController, animated: true)
        } else {
            print("Oh well...")
        }
    }
}

@available(iOS 13, *)
extension ViewController: CreditCardScannerViewControllerDelegate {

Swift Package Manager

  • In Xcode, add as Swift package with this URL: https://github.com/yhkaplan/credit-card-scanner.git

Carthage (Experimental)

  • Add this to Cartfile: github "yhkaplan/credit-card-scanner"
  • Follow instructions on Carthage README for integration without adding to copy files script
  • This framework is build as a static framework for Carthage, that's why it has the settings above
  • To build with Carthage yourself, run swift package generate-xcodeproj then run the necessary Carthage commands

Cocoapods

  • Support coming soon

Usage

  1. Add description to Info.plist Privacy - Camera Usage Description
    • Ex: $(PRODUCT_NAME) uses the camera to add credit card
  2. import CreditCardScanner
  3. Conform to CreditCardScannerViewControllerDelegate
  4. Present CreditCardScannerViewController and set its delegate
import CreditCardScanner

class ViewController: UIViewController, CreditCardScannerViewControllerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()

        let creditCardScannerViewController = CreditCardScannerViewController(delegate: self)
        present(creditCardScannerViewController, animated: true)
    }

    func creditCardScannerViewController(_ viewController: CreditCardScannerViewController, didErrorWith error: CreditCardScannerError) {
        viewController.dismiss(animated: true)
        print(error.errorDescription ?? "Unknown error")
    }

    func creditCardScannerViewController(_ viewController: CreditCardScannerViewController, didFinishWith card: CreditCard) {
        // Do something with credit card info
        print("\(card)")
    }

}

Trying out the Example app

# Install xcodegen if not present
$ brew install xcodegen
# Generate project
$ xcodegen

Alternatives

Card.io

  • Card.io
  • This was a good solution, but it has been unmaintained for a long time and is not fully open-source

CardScan

  • CardScan
  • Open-source and looks well made
  • Supports iOS 11/12 unlike CreditCardScanner
  • Costs money to use

Credits/Inspiration

This was a two person project by @po-miyasaka and @yhkaplan.

This project would not have been possible without Apple's example project (used with permission under an MIT license) demonstrating Vision and AVFoundation and Apple's other example project demonstrating a fully-featured photo app (also used with permission under an MIT license)

License

Licensed under MIT license. See LICENSE for more info.

credit-card-scanner's People

Contributors

cocoabagel avatar misterwell avatar po-miyasaka avatar yhkaplan avatar

Watchers

 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.