GithubHelp home page GithubHelp logo

yhkaplan / credit-card-scanner Goto Github PK

View Code? Open in Web Editor NEW
107.0 7.0 28.0 918 KB

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

License: Other

Swift 83.93% Makefile 0.91% Shell 12.29% 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 po-miyasaka avatar yhkaplan 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

credit-card-scanner's Issues

setting fonts

any change to move this variables to public or create public setup function?
it would be cool to be able not only to change the text of the titles, but also the fonts/color

    private var titleLabel = UILabel()
    private var subtitleLabel = UILabel()
    private var cancelButton = UIButton(type: .system)

Not picking name in some cards

I integrated it into my app but the result is not always correct. The name on the cards is missing in many card scans.

What is the possible solution to this?

Linker issues w/ Carthage archive

solutions

  • give up on making it a static library and go w/ regular dynamic one?
  • give up on making archive altogher
  • make sure Reg and Sukar are linked properly

manually

carthage fetch "https://github.com/yhkaplan/credit-card-scanner.git"
(cd Carthage/Checkouts/credit-card-scanner/ && swift package generate-xcodeproj)
carthage build --platform $PLATFORM_NAME credit-card-scanner
ld: warning: Could not find or use auto-linked framework 'Reg'
Undefined symbols for architecture x86_64:
  "Reg.Regex.init(stringLiteral: Swift.String) -> Reg.Regex", referenced from:
      closure #1 (__C.VNRequest, Swift.Error?) -> () in CreditCardScanner.ImageAnalyzer.requestHandler.getter : (__C.VNRequest, Swift.Error?) -> ()? in CreditCardScanner(ImageAnalyzer.o)
  "Reg.Regex.captures(in: Swift.String) -> [Swift.String]", referenced from:
      closure #1 (__C.VNRequest, Swift.Error?) -> () in CreditCardScanner.ImageAnalyzer.requestHandler.getter : (__C.VNRequest, Swift.Error?) -> ()? in CreditCardScanner(ImageAnalyzer.o)
  "Reg.Regex.firstMatch(in: Swift.String) -> Swift.String?", referenced from:
      closure #1 (__C.VNRequest, Swift.Error?) -> () in CreditCardScanner.ImageAnalyzer.requestHandler.getter : (__C.VNRequest, Swift.Error?) -> ()? in CreditCardScanner(ImageAnalyzer.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

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.