我正在使用iOS 11应用程序的触摸ID,我正在使用LA来确定身份验证是否失败,用户取消和使用返回如下:
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)
}
}
}
}
上面的代码有效,但我收到了这些警告:
' touchIDLockout'在iOS 11.0中已弃用:使用LAErrorBiometryLockout
' touchIDNotEnrolled'在iOS 11.0中已弃用:使用LAErrorBiometryNotEnrolled
' touchIDNotAvailable'在iOS 11.0中已弃用:使用LAErrorBiometryNotAvailable
现在我知道这些来自LAError,我的问题是,如何更新我的switch case语句以检查身份验证失败,用户取消和使用fallback?