|
|
@ -10,125 +10,126 @@ import UIKit |
|
|
|
import LocalAuthentication |
|
|
|
|
|
|
|
enum BiometricAuthenticationPolicy { |
|
|
|
case deviceOwnerAuthentication |
|
|
|
case deviceOwnerAuthenticationWithBiometrics |
|
|
|
case deviceOwnerAuthentication |
|
|
|
case deviceOwnerAuthenticationWithBiometrics |
|
|
|
} |
|
|
|
|
|
|
|
enum BiometricAuthenticationError: Error { |
|
|
|
case authenticationFailed |
|
|
|
case userCancel |
|
|
|
case userFallback |
|
|
|
case biometryNotAvailable |
|
|
|
case biometryNotEnrolled |
|
|
|
case biometryLockout |
|
|
|
case notBeConfigured |
|
|
|
|
|
|
|
var message: String { |
|
|
|
let msg: String |
|
|
|
|
|
|
|
switch self { |
|
|
|
case .authenticationFailed: |
|
|
|
msg = "There was a problem verifying your identity." |
|
|
|
case .userCancel: |
|
|
|
msg = "You pressed cancel." |
|
|
|
case .userFallback: |
|
|
|
msg = "You pressed password." |
|
|
|
case .biometryNotAvailable: |
|
|
|
msg = "Face ID/Touch ID is not available." |
|
|
|
case .biometryNotEnrolled: |
|
|
|
msg = "Face ID/Touch ID is not set up." |
|
|
|
case .biometryLockout: |
|
|
|
msg = "Face ID/Touch ID is locked." |
|
|
|
default: |
|
|
|
msg = "Face ID/Touch ID may not be configured" |
|
|
|
} |
|
|
|
return msg |
|
|
|
case authenticationFailed |
|
|
|
case userCancel |
|
|
|
case userFallback |
|
|
|
case biometryNotAvailable |
|
|
|
case biometryNotEnrolled |
|
|
|
case biometryLockout |
|
|
|
case notBeConfigured |
|
|
|
|
|
|
|
var message: String { |
|
|
|
let msg: String |
|
|
|
|
|
|
|
switch self { |
|
|
|
case .authenticationFailed: |
|
|
|
msg = "There was a problem verifying your identity." |
|
|
|
case .userCancel: |
|
|
|
msg = "You pressed cancel." |
|
|
|
case .userFallback: |
|
|
|
msg = "You pressed password." |
|
|
|
case .biometryNotAvailable: |
|
|
|
msg = "Face ID/Touch ID is not available." |
|
|
|
case .biometryNotEnrolled: |
|
|
|
msg = "Face ID/Touch ID is not set up." |
|
|
|
case .biometryLockout: |
|
|
|
msg = "Face ID/Touch ID is locked." |
|
|
|
default: |
|
|
|
msg = "Face ID/Touch ID may not be configured" |
|
|
|
} |
|
|
|
return msg |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protocol BiometricAuthenticationViewControllerDelegate: class{ |
|
|
|
func doSelectLocalAuthenticationPolicy(_ viewController: BiometricAuthenticationViewController) -> BiometricAuthenticationPolicy |
|
|
|
|
|
|
|
func viewController(_ viewController: BiometricAuthenticationViewController, informationTitleLabel titleLabel: UILabel ) |
|
|
|
|
|
|
|
func didComplete(_ viewController: BiometricAuthenticationViewController) |
|
|
|
|
|
|
|
func viewController(_ viewController: BiometricAuthenticationViewController, didFailWithError error: Error, errorMessage: String?) |
|
|
|
func doSelectLocalAuthenticationPolicy(_ viewController: BiometricAuthenticationViewController) -> BiometricAuthenticationPolicy |
|
|
|
|
|
|
|
func viewController(_ viewController: BiometricAuthenticationViewController, informationTitleLabel titleLabel: UILabel ) |
|
|
|
|
|
|
|
func didComplete(_ viewController: BiometricAuthenticationViewController) |
|
|
|
|
|
|
|
func viewController(_ viewController: BiometricAuthenticationViewController, didFailWithError error: Error, errorMessage: String?) |
|
|
|
} |
|
|
|
|
|
|
|
extension BiometricAuthenticationViewControllerDelegate { |
|
|
|
func doSelectLocalAuthenticationPolicy(_ viewController: BiometricAuthenticationViewController) -> BiometricAuthenticationPolicy{ |
|
|
|
return .deviceOwnerAuthentication |
|
|
|
} |
|
|
|
func doSelectLocalAuthenticationPolicy(_ viewController: BiometricAuthenticationViewController) -> BiometricAuthenticationPolicy{ |
|
|
|
return .deviceOwnerAuthentication |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
final class BiometricAuthenticationViewController: UIViewController, BiometricAuthenticationViewInterface { |
|
|
|
|
|
|
|
// MARK: Properties |
|
|
|
var presenter: BiometricAuthenticationModuleInterface? |
|
|
|
weak var delegate: BiometricAuthenticationViewControllerDelegate? |
|
|
|
|
|
|
|
private var isViewDidLoad = true |
|
|
|
// MARK: IBOutlets |
|
|
|
|
|
|
|
@IBOutlet private weak var biometricAuthenticationImageButton: UIButton! |
|
|
|
@IBOutlet private weak var informationLabel: UILabel! |
|
|
|
|
|
|
|
// MARK: VC's Life cycle |
|
|
|
|
|
|
|
override func viewDidLoad() { |
|
|
|
super.viewDidLoad() |
|
|
|
self.setup() |
|
|
|
|
|
|
|
// MARK: Properties |
|
|
|
var presenter: BiometricAuthenticationModuleInterface? |
|
|
|
weak var delegate: BiometricAuthenticationViewControllerDelegate? |
|
|
|
|
|
|
|
private var isViewDidLoad = true |
|
|
|
// MARK: IBOutlets |
|
|
|
|
|
|
|
@IBOutlet private weak var biometricAuthenticationImageButton: UIButton! |
|
|
|
@IBOutlet private weak var informationLabel: UILabel! |
|
|
|
|
|
|
|
// MARK: VC's Life cycle |
|
|
|
|
|
|
|
override func viewDidLoad() { |
|
|
|
super.viewDidLoad() |
|
|
|
self.setup() |
|
|
|
} |
|
|
|
|
|
|
|
override func viewDidAppear(_ animated: Bool) { |
|
|
|
super.viewDidAppear(animated) |
|
|
|
|
|
|
|
if self.isViewDidLoad{ |
|
|
|
self.showAuthentication() |
|
|
|
self.isViewDidLoad = false |
|
|
|
} |
|
|
|
|
|
|
|
override func viewDidAppear(_ animated: Bool) { |
|
|
|
super.viewDidAppear(animated) |
|
|
|
|
|
|
|
if self.isViewDidLoad{ |
|
|
|
self.showAuthentication() |
|
|
|
self.isViewDidLoad = false |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// MARK: IBActions |
|
|
|
|
|
|
|
@IBAction private func authenticationButtonTouch(_ sender: Any) { |
|
|
|
self.showAuthentication() |
|
|
|
} |
|
|
|
|
|
|
|
// MARK: Other Functions |
|
|
|
|
|
|
|
private func setup() { |
|
|
|
// all setup should be done here |
|
|
|
self.setUI() |
|
|
|
self.delegate?.viewController(self, informationTitleLabel: self.informationLabel) |
|
|
|
} |
|
|
|
|
|
|
|
private func setUI(){ |
|
|
|
setBackground() |
|
|
|
biometricAuthenticationImageButton.rounded() |
|
|
|
} |
|
|
|
|
|
|
|
private func setBackground(){ |
|
|
|
self.view.backgroundColor = AppConstants.themeRedColor |
|
|
|
} |
|
|
|
|
|
|
|
private func showAuthentication(){ |
|
|
|
} |
|
|
|
|
|
|
|
// MARK: IBActions |
|
|
|
|
|
|
|
@IBAction private func authenticationButtonTouch(_ sender: Any) { |
|
|
|
self.showAuthentication() |
|
|
|
} |
|
|
|
|
|
|
|
// MARK: Other Functions |
|
|
|
|
|
|
|
private func setup() { |
|
|
|
// all setup should be done here |
|
|
|
self.setUI() |
|
|
|
self.delegate?.viewController(self, informationTitleLabel: self.informationLabel) |
|
|
|
} |
|
|
|
|
|
|
|
private func setUI(){ |
|
|
|
setBackground() |
|
|
|
biometricAuthenticationImageButton.rounded() |
|
|
|
biometricAuthenticationImageButton.setTitle("bio_press_button_title_text".localized(), for: .normal) |
|
|
|
} |
|
|
|
|
|
|
|
private func setBackground(){ |
|
|
|
self.view.backgroundColor = AppConstants.themeRedColor |
|
|
|
} |
|
|
|
|
|
|
|
private func showAuthentication(){ |
|
|
|
|
|
|
|
guard |
|
|
|
let isUseBiometricAuth = KeyChain.shared.get(key: .biometricAuth), |
|
|
|
isUseBiometricAuth == "1" else { |
|
|
|
let error = BiometricAuthenticationError.biometryNotAvailable |
|
|
|
|
|
|
|
guard |
|
|
|
let isUseBiometricAuth = KeyChain.shared.get(key: .biometricAuth), |
|
|
|
isUseBiometricAuth == "1" else { |
|
|
|
let error = BiometricAuthenticationError.biometryNotAvailable |
|
|
|
|
|
|
|
self.delegate?.viewController( |
|
|
|
self, |
|
|
|
didFailWithError: error, |
|
|
|
errorMessage: error.message |
|
|
|
) |
|
|
|
return |
|
|
|
} |
|
|
|
self.presenter?.showBiometricAuthentication() |
|
|
|
self.delegate?.viewController( |
|
|
|
self, |
|
|
|
didFailWithError: error, |
|
|
|
errorMessage: error.message |
|
|
|
) |
|
|
|
return |
|
|
|
} |
|
|
|
self.presenter?.showBiometricAuthentication() |
|
|
|
} |
|
|
|
} |