Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yhkaplan/credit-card-scanner
An iOS library using the Vision API to read credit card information
https://github.com/yhkaplan/credit-card-scanner
Last synced: 3 months ago
JSON representation
An iOS library using the Vision API to read credit card information
- Host: GitHub
- URL: https://github.com/yhkaplan/credit-card-scanner
- Owner: yhkaplan
- License: other
- Created: 2020-07-23T10:11:31.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-02-26T16:12:11.000Z (almost 4 years ago)
- Last Synced: 2024-10-11T21:25:45.840Z (4 months ago)
- Language: Swift
- Size: 896 KB
- Stars: 112
- Watchers: 7
- Forks: 29
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# 💳 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](example.gif)
## 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````swift
#if canImport(CreditCardScanner)
import CreditCardScanner
#endifclass 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](https://github.com/Carthage/Carthage#if-youre-building-for-ios-tvos-or-watchos) 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`
1. `import CreditCardScanner`
1. Conform to `CreditCardScannerViewControllerDelegate`
1. Present `CreditCardScannerViewController` and set its delegate```swift
import CreditCardScannerclass 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
```sh
# Install xcodegen if not present
$ brew install xcodegen
# Generate project
$ xcodegen
```## Alternatives
### Card.io
- [Card.io](https://github.com/card-io/card.io-iOS-SDK)
- This was a good solution, but it has been unmaintained for a long time and is not fully open-source### CardScan
- [CardScan](https://github.com/getbouncer/cardscan-ios)
- 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](https://github.com/po-miyasaka) and [@yhkaplan](https://github.com/yhkaplan).
This project would not have been possible without Apple's [example project](https://developer.apple.com/documentation/vision/reading_phone_numbers_in_real_time) (used with permission under an MIT license) demonstrating Vision and AVFoundation and Apple's [other example project](https://developer.apple.com/documentation/avfoundation/cameras_and_media_capture/avcam_building_a_camera_app) demonstrating a fully-featured photo app (also used with permission under an MIT license)
## License
Licensed under MIT license. See [LICENSE](LICENSE) for more info.