diff --git a/Example/ViewController.swift b/Example/ViewController.swift index ffea2ed..701cb88 100644 --- a/Example/ViewController.swift +++ b/Example/ViewController.swift @@ -21,8 +21,7 @@ class ViewController: UIViewController { passwordView?.delegate = self passwordView?.titleToRequestAuthentication = "Please, identify your self!" - passwordView?.start(enableBiometrics: false) - passwordView?.changeExistingPassword() + passwordView?.start(enableBiometrics: true) // when user wants to change the registered password... you just use this method and mbspasswordview will take care of it and gives you the new password on the password delegate method. //passwordView?.changeExistingPassword() @@ -58,19 +57,6 @@ extension ViewController: MBSPasswordDelegate { print("Authenticated by password and biometrics. Password:\(password)") case .error(let error): print("Error to authenticate by biometrics...") - if let error = (error as? MBSAuthenticationIDError) { - switch error { - case .notRegistered: - print("notRegistered") - case .invalidID: - print("invalidID") - case .notSupported: - print("device or so notSupported") - case .canceled: - print("canceled") - - } - } } } } diff --git a/MBSPasswordView/Classes/Protocols/MBSAuthenticatable.swift b/MBSPasswordView/Classes/Protocols/MBSAuthenticatable.swift index e121b31..ca567e3 100644 --- a/MBSPasswordView/Classes/Protocols/MBSAuthenticatable.swift +++ b/MBSPasswordView/Classes/Protocols/MBSAuthenticatable.swift @@ -10,10 +10,7 @@ import Foundation import LocalAuthentication public enum MBSAuthenticationIDError: Error { - case notRegistered - case canceled case notSupported - case invalidID } public protocol MBSAuthenticatable { diff --git a/MBSPasswordView/Classes/UI/MBSPasswordView.swift b/MBSPasswordView/Classes/UI/MBSPasswordView.swift index b56e46e..a3ce3b6 100644 --- a/MBSPasswordView/Classes/UI/MBSPasswordView.swift +++ b/MBSPasswordView/Classes/UI/MBSPasswordView.swift @@ -135,7 +135,7 @@ extension MBSPasswordView: MBSTopPasswordDelegate, Shakable { public func password(_ result: [String]) { registerPassword(result) disableViews() - callBiometricsIfEnabled(result) + authenticateUser(result) } public func invalidMatch() { shakeView() @@ -287,6 +287,21 @@ extension MBSPasswordView { // MARK: - Request Authentication extension MBSPasswordView: MBSAuthenticatable { private func callBiometricsIfEnabled(_ password: [String]) { + if enableBiometricsAuthentication { + self.authenticateByBiometrics(title: titleToRequestAuthentication) { result in + switch result { + case .success: + self.delegate?.passwordFromBiometrics(MBSPasswordResult.success(password)) + case .error(let error): + // we won't request on the next try... User should try by password + self.enableBiometricsAuthentication = false + self.delegate?.passwordFromBiometrics(MBSPasswordResult.error(error)) + } + } + } + } + + private func authenticateUser(_ password: [String]) { if enableBiometricsAuthentication { self.authenticateByBiometrics(title: titleToRequestAuthentication) { result in switch result {