GithubHelp home page GithubHelp logo

rickhohler / card-reader-ios Goto Github PK

View Code? Open in Web Editor NEW

This project forked from khalid-asad/card-reader-ios

0.0 0.0 0.0 734 KB

A credit card reader and parser for iOS Using Native Vision/VisionKit

License: MIT License

Swift 100.00%

card-reader-ios's Introduction

iOS SPM compatible License Swift 5.0

card-reader-ios

A credit card reader and parser for iOS Using Native Vision/VisionKit

May-14-2021.00-43-17.mp4

Instructions

  • Hold camera up to a card and stay still until it gets recoginized and a picture gets taken.
  • Hit Save, and the results should get processed.

Usage as Framework

There are 2 options to present:

Simply navigate to or present CardResultsView as a sheet or View:

var body: some View {
	CardFormView(colors: [.green, .blue, .black], completion: { cardDetails in 
        print("Card Number:\n\(cardDetails.number ?? "")")
        print("Expiry Date:\n\(cardDetails.expiryDate ?? "")")
        print("Name:\n\(cardDetails.name ?? "")")
        print("Name:\n\(cardDetails.cvcNumber ?? "")")
        print("Card Type:\n\(cardDetails.type.rawValue)")
        print("Card Industry:\n\(cardDetails.industry.rawValue)")
    })
}

Only the card reader view:

Add this code in your SwiftUI Main View underneath your main StackView/ScrollView/NavigationView:

.sheet(isPresented: $isShowingSheet) {
    CardReaderView() { cardDetails in
        self.cardDetails = cardDetails
        isShowingSheet.toggle()
    }
    .edgesIgnoringSafeArea(.all)
}

Create two state variables to handle sheet presentation and to hold the card details result from the closure:

@State private var isShowingSheet = false
@State private var cardDetails: CardDetails?

Add the UI Presentation logic of the CardDetails however you see fit:

if let cardDetails = cardDetails {
    Text("Card Number:\n\(cardDetails.number ?? "")")
    Text("Expiry Date:\n\(cardDetails.expiryDate ?? "")")
    Text("Name:\n\(cardDetails.name ?? "")")
    Text("Card Type:\n\(cardDetails.type.rawValue)")
    Text("Card Industry:\n\(cardDetails.industry.rawValue)")
}

Finally, present the CardReaderView by toggling the sheet (preferably from the closure of a button action):

Button { isShowingSheet.toggle() } label: { Text("Tap to Start Credit Card reading!") } 

Notes

  • I will continue to maintain this repo and keep adding new features.
  • If you see a bug or have an idea for a new feature, please raise an issue or pull request :)

License

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

card-reader-ios's People

Contributors

khalid-asad 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.