Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // LocalAuthenticationService.swift
- // Touch ID and Face ID
- //
- // Created by Elias Paulino on 06/09/19.
- // Copyright © 2019 Anderson Alencar. All rights reserved.
- //
- import Foundation
- import LocalAuthentication
- enum AuthError: Error {
- case BiometricsEvaluationIsntAvaliable, AuthenticationNotGranted
- }
- struct AuthenticationService {
- let laContext: LAContext = .init()
- // check if the iphone has auth support
- var biometricsIsAvaliable: Bool {
- var checkingError: NSError?
- return laContext.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &checkingError) && checkingError == nil
- }
- // checks if ther user is the iPhone owner.
- func checkUserIdentification(reason: String, completion: @escaping (Result<Bool, Error>) -> Void) {
- guard biometricsIsAvaliable else {
- completion(.failure(AuthError.BiometricsEvaluationIsntAvaliable))
- return
- }
- laContext.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: reason) { (sucess, error) in
- if let error = error {
- completion(.failure(error))
- return
- }
- completion(.success(sucess))
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement