• Stars
    star
    109
  • Rank 319,077 (Top 7 %)
  • Language
    Swift
  • License
    Other
  • Created over 4 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

๐Ÿ’ณ 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.

More Repositories

1

DoubleSlider

A UISlider replacement with two draggable thumbs
Swift
53
star
2

scaffold

Tool for generating code from Stencil templates, similar to rails gen
Swift
37
star
3

Shop

Example e-commerce app with a modern architecture and view layout. Mixed UIKit and SwiftUI.
Swift
12
star
4

dotfiles

Dotfiles for iOS and Golang development with Neovim, Zsh, tmux and more
Shell
6
star
5

CurlGen

ฮผframework for debugging with URLRequests, converting them to cURL commands
Swift
4
star
6

presentations

Repo of all my presentations since Sept of 2020
4
star
7

Reg

A convenient Ruby-like wrapper for NSRegularExpression
Swift
4
star
8

japanese-holiday-action

Offers outputs to check if it's a Japanese public holiday and which one
JavaScript
4
star
9

automation-presentation-2019-02-21

3
star
10

carthage_audit

A tool to check for keywords that indicate a vulnerability was patched and found
Ruby
2
star
11

StarWarsLexicon

iOS app for looking up info about Star Wars characters, vehicles, etc
Swift
2
star
12

automation-presentation-2019-07-20

1
star
13

writing_an_interpreter_in_go

Based on eponymous book
Go
1
star
14

swift-migration-presentation-2019-07-30

Presentation on migrating from Objective-C to Swift
1
star
15

pokemon-swiftui

A sample app to practice SwiftUI + Combine
Swift
1
star
16

parser-combinator-presentation-2019-12-03

Swift
1
star
17

fastlane-plugin-swift_doc

Generate documentation, documentation coverage, or a class diagram using SwiftDoc
Ruby
1
star
18

LattnerBot

SlackBot made in Swift to announce what percentage of your codebase is Obj-C and what percentage is Swift
Swift
1
star
19

swift-formatting-scripts

Convenient scripts to run all or limited rules for SwiftFormat and SwiftLint, etc
Swift
1
star
20

hanzomon-scraper

Go
1
star
21

MoonWalker

A simple iOS Walkthrough framework
Swift
1
star