Skip to content

Commit

Permalink
Added new string interface that inclues all the strings
Browse files Browse the repository at this point in the history
  • Loading branch information
kingst committed Sep 17, 2019
1 parent 6c6bb5d commit d989a76
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
24 changes: 23 additions & 1 deletion CardScan/Classes/ScanViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ import UIKit
@objc func skipButton() -> String
}

// The FullScanStringsDataSource protocol defines all of the strings
// that the viewcontroller uses. As we add more strings we will update
// this protocol, which will require you to update your integration on
// an update that includes new strings.
//
// If you prefer to just set the main strings on the ScanViewController
// the ScanStringsDataSource protocol is stable and won't change, but
// might be incomplete.
@objc public protocol FullScanStringsDataSource: ScanStringsDataSource {
@objc func denyPermissionTitle() -> String
@objc func denyPermissionMessage() -> String
}

@objc public class CreditCard: NSObject {
@objc public var number: String
@objc public var expiryMonth: String?
Expand Down Expand Up @@ -105,6 +118,8 @@ import UIKit
@IBOutlet weak var torchButton: UIButton!
@IBOutlet weak var cornerView: CornerView!
var cornerBorderColor = UIColor.green.cgColor
var denyPermissionTitle = "Need camera accesss"
var denyPermissionMessage = "Please enable camera access in your settings to scan your card"

var calledDelegate = false
var needToShowDenyAlert = false
Expand Down Expand Up @@ -170,6 +185,13 @@ import UIKit
self.positionCardLabel.text = dataSource.positionCard()
self.skipButton.setTitle(dataSource.skipButton(), for: .normal)
self.backButton.setTitle(dataSource.backButton(), for: .normal)

guard let fullDataSource = dataSource as? FullScanStringsDataSource else {
return
}

self.denyPermissionMessage = fullDataSource.denyPermissionMessage()
self.denyPermissionTitle = fullDataSource.denyPermissionTitle()
}

func setUiCustomization() {
Expand Down Expand Up @@ -210,7 +232,7 @@ import UIKit
}

func showDenyAlert() {
let alert = UIAlertController(title: "Need camera accesss", message: "Please enable camera access in your settings to scan your card", preferredStyle: .alert)
let alert = UIAlertController(title: self.denyPermissionTitle, message: self.denyPermissionMessage, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in
switch action.style{
case .default:
Expand Down
4 changes: 3 additions & 1 deletion Example/CardScan/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import UIKit
import CardScan

class ViewController: UIViewController, ScanEvents, ScanDelegate, ScanStringsDataSource, TestingImageDataSource {
class ViewController: UIViewController, ScanEvents, ScanDelegate, FullScanStringsDataSource, TestingImageDataSource {

let testImages = [UIImage(imageLiteralResourceName: "frame0"),
UIImage(imageLiteralResourceName: "frame19"),
Expand All @@ -34,6 +34,8 @@ class ViewController: UIViewController, ScanEvents, ScanDelegate, ScanStringsDat
func positionCard() -> String { return "New Position Card" }
func backButton() -> String { return "New Back" }
func skipButton() -> String { return "New Skip" }
func denyPermissionTitle() -> String { return "New Deny" }
func denyPermissionMessage() -> String { return "New Deny Message" }

func userDidSkip(_ scanViewController: ScanViewController) {
self.dismiss(animated: true)
Expand Down

0 comments on commit d989a76

Please sign in to comment.