Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion PasscodeLock/PasscodeLock/ChangePasscodeState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct ChangePasscodeState: PasscodeLockStateType {
let title: String
let description: String
let isCancellableAction = true
var isTouchIDAllowed = false
var isBiometricAuthAllowed: Bool = false

init() {

Expand Down
2 changes: 1 addition & 1 deletion PasscodeLock/PasscodeLock/ConfirmPasscodeState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct ConfirmPasscodeState: PasscodeLockStateType {
let title: String
let description: String
let isCancellableAction = true
var isTouchIDAllowed = false
var isBiometricAuthAllowed: Bool = false

fileprivate var passcodeToConfirm: [String]

Expand Down
2 changes: 1 addition & 1 deletion PasscodeLock/PasscodeLock/EnterPasscodeState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct EnterPasscodeState: PasscodeLockStateType {
let title: String
let description: String
let isCancellableAction: Bool
var isTouchIDAllowed = true
var isBiometricAuthAllowed = true

static let incorrectPasscodeAttemptsKey = "incorrectPasscodeAttempts"
static var incorrectPasscodeAttempts: Int {
Expand Down
29 changes: 20 additions & 9 deletions PasscodeLock/PasscodeLock/PasscodeLock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ open class PasscodeLock: PasscodeLockType {
return lockState
}

open var isTouchIDAllowed: Bool {
return isTouchIDEnabled() && configuration.isTouchIDAllowed && lockState.isTouchIDAllowed
open var isBiometricAuthAllowed: Bool {
return isBiometricAuthEnabled() && configuration.isBiometricAuthAllowed && lockState.isBiometricAuthAllowed
}

fileprivate var lockState: PasscodeLockStateType
Expand Down Expand Up @@ -67,26 +67,37 @@ open class PasscodeLock: PasscodeLockType {

open func authenticateWithBiometrics() {

guard isTouchIDAllowed else { return }
guard isBiometricAuthAllowed else { return }

let context = LAContext()
let reason: String
if let configReason = configuration.touchIdReason {
if let configReason = configuration.biometricAuthReason {
reason = configReason
} else {
reason = localizedStringFor("PasscodeLockTouchIDReason", comment: "TouchID authentication reason")
if #available(iOS 11, *) {
switch(context.biometryType) {
case .touchID:
reason = localizedStringFor("PasscodeLockTouchIDReason", comment: "Authentication required to proceed")
case .faceID:
reason = localizedStringFor("PasscodeLockFaceIDReason", comment: "Authentication required to proceed")
default:
reason = localizedStringFor("PasscodeLockBiometricAuthReason", comment: "Authentication required to proceed")
}
} else {
reason = localizedStringFor("PasscodeLockBiometricAuthReason", comment: "Authentication required to proceed")
}
}

context.localizedFallbackTitle = localizedStringFor("PasscodeLockTouchIDButton", comment: "TouchID authentication fallback button")
context.localizedFallbackTitle = localizedStringFor("PasscodeLockBiometricAuthButton", comment: "Biometric authentication fallback button")

context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: reason) {
success, error in

self.handleTouchIDResult(success)
self.handleBiometricAuthResult(success)
}
}

fileprivate func handleTouchIDResult(_ success: Bool) {
fileprivate func handleBiometricAuthResult(_ success: Bool) {

DispatchQueue.main.async {

Expand All @@ -97,7 +108,7 @@ open class PasscodeLock: PasscodeLockType {
}
}

fileprivate func isTouchIDEnabled() -> Bool {
fileprivate func isBiometricAuthEnabled() -> Bool {

let context = LAContext()

Expand Down
2 changes: 1 addition & 1 deletion PasscodeLock/PasscodeLock/SetPasscodeState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct SetPasscodeState: PasscodeLockStateType {
let title: String
let description: String
let isCancellableAction = true
var isTouchIDAllowed = false
var isBiometricAuthAllowed: Bool = false

init(title: String, description: String) {

Expand Down
16 changes: 8 additions & 8 deletions PasscodeLock/PasscodeLockViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ open class PasscodeLockViewController: UIViewController, PasscodeLockTypeDelegat
@IBOutlet open var placeholders: [PasscodeSignPlaceholderView] = [PasscodeSignPlaceholderView]()
@IBOutlet open weak var cancelButton: UIButton?
@IBOutlet open weak var deleteSignButton: UIButton?
@IBOutlet open weak var touchIDButton: UIButton?
@IBOutlet open weak var biometricAuthButton: UIButton!
@IBOutlet open weak var placeholdersX: NSLayoutConstraint?

open var successCallback: ((_ lock: PasscodeLockType) -> Void)?
open var dismissCompletionCallback: (()->Void)?
open var animateOnDismiss: Bool
open var notificationCenter: NotificationCenter?

internal let passcodeConfiguration: PasscodeLockConfigurationType
internal var passcodeLock: PasscodeLockType
internal var isPlaceholdersAnimationCompleted = true
Expand All @@ -48,7 +48,7 @@ open class PasscodeLockViewController: UIViewController, PasscodeLockTypeDelegat

// MARK: - Initializers

public init(state: PasscodeLockStateType, configuration: PasscodeLockConfigurationType, animateOnDismiss: Bool = true, nibName: String = "PasscodeLockView", bundle: Bundle? = nil) {
public init(state: PasscodeLockStateType, configuration: PasscodeLockConfigurationType, animateOnDismiss: Bool = true, nibName: String = "PasscodeLockView", bundle: Bundle? = nil) {

self.animateOnDismiss = animateOnDismiss

Expand Down Expand Up @@ -96,7 +96,7 @@ open class PasscodeLockViewController: UIViewController, PasscodeLockTypeDelegat
open override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)

if shouldTryToAuthenticateWithBiometrics && passcodeConfiguration.shouldRequestTouchIDImmediately {
if shouldTryToAuthenticateWithBiometrics && passcodeConfiguration.shouldRequestBiometricAuthImmediately {

authenticateWithBiometrics()
}
Expand All @@ -107,7 +107,7 @@ open class PasscodeLockViewController: UIViewController, PasscodeLockTypeDelegat
titleLabel?.text = passcodeLock.state.title
descriptionLabel?.text = passcodeLock.state.description
cancelButton?.isHidden = !passcodeLock.state.isCancellableAction
touchIDButton?.isHidden = !passcodeLock.isTouchIDAllowed
biometricAuthButton?.isHidden = !passcodeLock.isBiometricAuthAllowed
}

// MARK: - Events
Expand All @@ -126,7 +126,7 @@ open class PasscodeLockViewController: UIViewController, PasscodeLockTypeDelegat

@objc open func appWillEnterForegroundHandler(_ notification: Notification) {

if passcodeConfiguration.shouldRequestTouchIDImmediately {
if passcodeConfiguration.shouldRequestBiometricAuthImmediately {
authenticateWithBiometrics()
}
}
Expand Down Expand Up @@ -155,7 +155,7 @@ open class PasscodeLockViewController: UIViewController, PasscodeLockTypeDelegat
passcodeLock.removeSign()
}

@IBAction func touchIDButtonTap(_ sender: UIButton) {
@IBAction func biometricAuthButtonTap(_ sender: UIButton) {

passcodeLock.authenticateWithBiometrics()
}
Expand All @@ -164,7 +164,7 @@ open class PasscodeLockViewController: UIViewController, PasscodeLockTypeDelegat

guard passcodeConfiguration.repository.hasPasscode else { return }

if passcodeLock.isTouchIDAllowed {
if passcodeLock.isBiometricAuthAllowed {

passcodeLock.authenticateWithBiometrics()
}
Expand Down
6 changes: 3 additions & 3 deletions PasscodeLock/Protocols/PasscodeLockConfigurationType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ public protocol PasscodeLockConfigurationType {

var repository: PasscodeRepositoryType {get}
var passcodeLength: Int {get}
var isTouchIDAllowed: Bool {get set}
var shouldRequestTouchIDImmediately: Bool {get}
var touchIdReason: String? {get set}
var isBiometricAuthAllowed: Bool {get set}
var shouldRequestBiometricAuthImmediately: Bool {get}
var biometricAuthReason: String? {get set}
var maximumInccorectPasscodeAttempts: Int {get}
}

Expand Down
2 changes: 1 addition & 1 deletion PasscodeLock/Protocols/PasscodeLockStateType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public protocol PasscodeLockStateType {
var title: String {get}
var description: String {get}
var isCancellableAction: Bool {get}
var isTouchIDAllowed: Bool {get}
var isBiometricAuthAllowed: Bool {get}

mutating func acceptPasscode(_ passcode: [String], fromLock lock: PasscodeLockType)
}
2 changes: 1 addition & 1 deletion PasscodeLock/Protocols/PasscodeLockType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public protocol PasscodeLockType {
var configuration: PasscodeLockConfigurationType {get}
var repository: PasscodeRepositoryType {get}
var state: PasscodeLockStateType {get}
var isTouchIDAllowed: Bool {get}
var isBiometricAuthAllowed: Bool {get}

func addSign(_ sign: String)
func removeSign()
Expand Down
Loading