Skip to content

Commit

Permalink
chore: Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronlab committed Nov 14, 2020
1 parent 3367092 commit dba15d6
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 1 deletion.
129 changes: 128 additions & 1 deletion README.md
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.
Binary file added preview.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit dba15d6

Please sign in to comment.