0

I am using touch id with my iOS 11 app and I am using LA to determine if authentication failed, user cancels and usefallback like so:

import Foundation
import LocalAuthentication

class TouchIDAuth {

    let context = LAContext()

    func canEvaluatePolicy() -> Bool {
        return context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil)
    }

    func authenticateUser(completion: @escaping (NSNumber?) -> Void) {

        guard canEvaluatePolicy() else {
            completion(0)
            return
        }

        context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics,
                               localizedReason: "Logging in with Touch ID") { (success, evaluateError) in
                                if success {
                                    DispatchQueue.main.async {
                                        completion(nil)
                                    }
                                } else {

                                    let response: NSNumber

                                    switch evaluateError {
                                    case LAError.authenticationFailed?:
                                        response = 2
                                    case LAError.userCancel?:
                                        response = 3
                                    case LAError.userFallback?:
                                        response = 4
                                    default:
                                        response = 1
                                    }

                                    completion(response)

                                }
        }
    }

}

The code above works, but I am getting these warnings:

'touchIDLockout' was deprecated in iOS 11.0: use LAErrorBiometryLockout

'touchIDNotEnrolled' was deprecated in iOS 11.0: use LAErrorBiometryNotEnrolled

'touchIDNotAvailable' was deprecated in iOS 11.0: use LAErrorBiometryNotAvailable

Now I know these are coming from LAError, my question is, how do I update my switch case statement to check for authentication failed, user cancels and usefallback?

user979331
  • 11,039
  • 73
  • 223
  • 418
  • I've seen that answer, but it does not help. I am tyring to use kLAErrorAuthenticationFailed but that returns an int and not an error that would match evaluateError – user979331 Jun 07 '18 at 16:13
  • Have a look at https://stackoverflow.com/a/41632912/1187415. – Martin R Jun 07 '18 at 22:38

0 Answers0