Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. //
  2. // LocalAuthenticationService.swift
  3. // Touch ID and Face ID
  4. //
  5. // Created by Elias Paulino on 06/09/19.
  6. // Copyright © 2019 Anderson Alencar. All rights reserved.
  7. //
  8.  
  9. import Foundation
  10. import LocalAuthentication
  11.  
  12. enum AuthError: Error {
  13. case BiometricsEvaluationIsntAvaliable, AuthenticationNotGranted
  14. }
  15.  
  16. struct AuthenticationService {
  17. let laContext: LAContext = .init()
  18.  
  19. // check if the iphone has auth support
  20. var biometricsIsAvaliable: Bool {
  21. var checkingError: NSError?
  22. return laContext.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &checkingError) && checkingError == nil
  23. }
  24.  
  25. // checks if ther user is the iPhone owner.
  26. func checkUserIdentification(reason: String, completion: @escaping (Result<Bool, Error>) -> Void) {
  27. guard biometricsIsAvaliable else {
  28. completion(.failure(AuthError.BiometricsEvaluationIsntAvaliable))
  29. return
  30. }
  31.  
  32. laContext.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: reason) { (sucess, error) in
  33. if let error = error {
  34. completion(.failure(error))
  35. return
  36. }
  37.  
  38. completion(.success(sucess))
  39. }
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement