-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
128 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,130 @@ | ||
![SwiftPM compatible](https://img.shields.io/badge/SwiftPM-compatible-brightgreen.svg) | ||
![Platform](https://img.shields.io/cocoapods/p/SwiftOCR.svg?style=flat) | ||
|
||
# SweetCardScanner | ||
|
||
A description of this package. | ||
SweetCardScanner is a fast and simple Card Scanner library written in Swift, based on [CreditCardScanner](https://github.com/yhkaplan/credit-card-scanner) and [Reg](https://github.com/yhkaplan/Reg) libraries by [@yhkaplan](https://github.com/yhkaplan) so that users can pay much more easily by capturing their credit/debit card with their rear camera. | ||
|
||
<center> | ||
<img src="./preview.gif" width="260"> | ||
</center> | ||
|
||
## Requirements | ||
|
||
- iOS 13.0+ (due to SwiftUI, Vision Framework) | ||
- Tesed on iOS 14.1 with iPhon X | ||
|
||
## Installation | ||
|
||
- In Xcode, add SwiftPM with the URL of this repository: | ||
|
||
```http | ||
https://github.com/aaronLab/SweetCardScanner.git | ||
``` | ||
|
||
## Usage | ||
|
||
1. Add `NSCameraUsageDescription` into `Info.plist` for Camera Useage Description. | ||
2. `import SweetCardScanner` on top of the `ContentView.swift`. | ||
3. Now, you can use like `SweetCardScanner()` inside of the body. | ||
4. Also, you can use completion clousures, such as `.onDismiss`, `.onError`, `onSuccess` right after `SweetCardScanner()` like below. | ||
|
||
```Swift | ||
var body: some View { | ||
SweetCardScanner() | ||
.onError { error in | ||
// This 'error' above gives you 'CreditCardScannerError' | ||
print(error) | ||
} | ||
.onSuccess { card in | ||
// This card above gives you 'CreditCard' | ||
print(card) | ||
} | ||
} | ||
``` | ||
|
||
## CreditCardScannerError | ||
|
||
```Swift | ||
public struct CreditCardScannerError: LocalizedError { | ||
public enum Kind { case cameraSetup, photoProcessing, authorizationDenied, capture } | ||
public var kind: Kind | ||
public var underlyingError: Error? | ||
public var errorDescription: String? { (underlyingError as? LocalizedError)?.errorDescription } | ||
} | ||
``` | ||
|
||
## CreditCard | ||
|
||
```Swift | ||
public struct CreditCard { | ||
public var number: String? | ||
public var name: String? | ||
public var expireDate: DateComponents? | ||
} | ||
``` | ||
|
||
## Example | ||
|
||
You can customize your own view with SweetCardScanner, and SwiftUI like below. | ||
|
||
```Swift | ||
import SwiftUI | ||
import SweetCardScanner | ||
|
||
struct ContentView: View { | ||
// MARK: - PROPERTIES | ||
|
||
@State var navigationStatus: NavigationStatus? = .ready | ||
@State var card: CreditCard? | ||
|
||
// MARK: - BODY | ||
|
||
var body: some View { | ||
|
||
NavigationView { | ||
|
||
GeometryReader { geometry in | ||
|
||
ZStack { | ||
|
||
NavigationLink( | ||
destination: ResultView(card: card), | ||
tag: NavigationStatus.pop, | ||
selection: $navigationStatus) { | ||
EmptyView() | ||
} | ||
|
||
SweetCardScanner() | ||
.onError { err in | ||
print(err) | ||
} | ||
.onSuccess { card in | ||
self.card = card | ||
self.navigationStatus = .pop | ||
} | ||
|
||
RoundedRectangle(cornerRadius: 16) | ||
.stroke() | ||
.foregroundColor(.white) | ||
.padding(16) | ||
.frame(width: geometry.size.width, height: geometry.size.width * 0.63, alignment: .center) | ||
|
||
} //: ZSTACK | ||
|
||
} //: GEOMETRY | ||
|
||
} //: NAVIGATION | ||
|
||
} | ||
} | ||
|
||
// MARK: - NavigationStatus | ||
enum NavigationStatus { | ||
case ready, pop | ||
} | ||
``` | ||
|
||
## License | ||
|
||
Licensed under [MIT](https://github.com/aaronLab/SweetCardScanner/blob/main/LICENSE) license. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.