Rename TouchID to biometrics

This commit is contained in:
Igor Kislyuk 2018-03-23 16:37:03 +03:00
parent 27f42e55a1
commit f612914307
4 changed files with 29 additions and 28 deletions

View File

@ -154,11 +154,7 @@ open class BasePassCodeViewController: UIViewController, ConfigurableController
return
}
viewModel.touchIdService?.authenticateByTouchId(description: description) { [weak self] isSuccess in
if isSuccess {
self?.viewModel.authSucceed(.touchId)
}
}
viewModel.authenticateUsingBiometrics(with: description)
}
private func resetUI() {

View File

@ -37,8 +37,8 @@ open class BasePassCodeViewModel: BaseViewModel {
public let disposeBag = DisposeBag()
/// TouchId service, which can answer if user is authorized by finger
public let touchIdService: TouchIDService?
/// Service that can answer if user is authorized by biometrics
public let biometricsService = BiometricsService()
/// Contains configuration for pass code operations
public let passCodeConfiguration: PassCodeConfiguration
@ -59,13 +59,9 @@ open class BasePassCodeViewModel: BaseViewModel {
private lazy var passCodeHolder: PassCodeHolderProtocol = PassCodeHolderBuilder.build(with: self.controllerType)
public init(controllerType: PassCodeControllerType,
passCodeConfiguration: PassCodeConfiguration,
touchIdService: TouchIDService? = nil) {
public init(controllerType: PassCodeControllerType, passCodeConfiguration: PassCodeConfiguration) {
self.controllerType = controllerType
self.passCodeConfiguration = passCodeConfiguration
self.touchIdService = touchIdService
bindViewModel()
}
@ -125,6 +121,16 @@ open class BasePassCodeViewModel: BaseViewModel {
passCodeHolder.reset()
}
public func authenticateUsingBiometrics(with description: String) {
biometricsService.authenticateWithBiometrics(with: description) { [weak self] success, error in
if success {
self?.authSucceed(.touchId)
} else {
self?.authFailed(with: error)
}
}
}
// MARK: - HAVE TO OVERRIDE
/// Override to check if entered pass code is equal to stored
@ -133,11 +139,16 @@ open class BasePassCodeViewModel: BaseViewModel {
return false
}
/// Handler called after successful authentication
/// Method is called after successful authentication
open func authSucceed(_ type: PassCodeAuthType) {
assertionFailure("You should override this method: authSucceed(_ type: PassCodeAuthType)")
}
/// Called when authentication failed
open func authFailed(with: Error?) {
assertionFailure("You should override this method: authFailed(with: Error)")
}
// MARK: - Biometrics
/// Posibility to use biometrics for authentication

View File

@ -59,8 +59,6 @@ open class BasePassCodeService {
return keychain[Keys.passCodeHash]
}
}
public extension BasePassCodeService {

View File

@ -22,34 +22,30 @@
import LocalAuthentication
public typealias TouchIDServiceAuthHandler = (Bool) -> Void
public typealias BiometricsAuthHandler = (Bool, Error?) -> Void
/// Represents service that provides access to authentication via touch id
public class TouchIDService {
/// Service that provide access to authentication via biometric
public final class BiometricsService {
private lazy var laContext: LAContext = {
return LAContext()
}()
private lazy var laContext = LAContext()
public init() {}
/// Indicates is it possible to authenticate on this device via touch id
public var canAuthenticateByTouchId: Bool {
public var canAuthenticateWithBiometrics: Bool {
return laContext.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil)
}
/**
Initiates system touch id authentication process
Initiates system biometrics authentication process
- parameters:
- description: prompt on the system alert that describes what for user should attach finger to device
- authHandler: callback, with parameter, indicates if user authenticate successfuly
*/
public func authenticateByTouchId(description: String, authHandler: @escaping TouchIDServiceAuthHandler) {
laContext.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics,
localizedReason: description) { success, _ in
authHandler(success)
public func authenticateWithBiometrics(with description: String, authHandler: @escaping BiometricsAuthHandler) {
laContext.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: description) { success, error in
authHandler(success, error)
}
}