Swiftpack.co -  gymshark/ios-card-scan as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
gymshark/ios-card-scan
iOS Credit/Debit card scanner, built using Apple's Vision Framework.
.package(url: "https://github.com/gymshark/ios-card-scan.git", from: "1.0.4")

SharkCardScan

SharkCardScan is a Credit/Debit Card scanner built using Apple's Vision Framework.

SharkCardScan allows you to quickly implement a card scanner inside of your own app.

SharkCardScan is built and maintained with love by the Gymshark Engineering Team 💙📱

Usage

It's possible to get started quickly with the following snippet.

        let scannerVC = SharkCardScanViewController(viewModel: CardScanViewModel(noPermissionAction: { [weak self] in
            
            self?.showNoPermissionAlert()
            
        }, successHandler: { (response) in
            print("Expiry 💣: \(response.expiry ?? "")")
            print("Card Number 💳: \(response.number)")
            print("Holder name 🕺: \(response.holder ?? "")")
        }))
        

Here we handle the No Camera Permission error, from the ViewModeland our successHandler is called upon receipt of finding a card number, and the expiry and card holders name, albeit, we can call success if only a valid card number is found.

Styling

SharkCardScanViewController initialiser takes a default parameter for styling, which you can specify your own, if you wish to amend fonts/colours.

SharkCardScanViewController(viewModel: CardScanViewModel{...}, styling: MyOwnCardScannerStyling())

CardScanStyling is a protocol, your styling struct must conform too with the following properties you have to set;


public protocol CardScanStyling {
    var instructionLabelStyling: LabelStyling { get set }
    var cardNumberLabelStyling: LabelStyling { get set }
    var expiryLabelStyling: LabelStyling { get set }
    var holderLabelStyling: LabelStyling { get set }
    var backgroundColor: UIColor { get set }
}

NB: By using the default parameter, and using our DefaultStyling struct instance, the font will only have fixed sizes, for now, rather than being dynamic - one for us to fix later (or send us a PR?!)

Other Customisations

ACardScanViewModel has a instructionText property, if you wish to override the default instruction text that is shown on the viewer.

Installation

Swift Package Manager (SPM) To install SharkCardScan using Swift Package Manager you can follow the tutorial published by Apple using the URL for the SharkCardScan repo with the current version:

  1. In Xcode, select “File” → “Swift Packages” → “Add Package Dependency”
  2. Enter https://github.com/gymshark/ios-card-scan.git

GitHub

link
Stars: 8
Last commit: 2 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics