在显示Touch ID提示时,是否可以立即为用户提供输入密码的机会?

时间:2016-05-08 23:19:21

标签: ios cocoa-touch ios9 touch-id

当提供Touch ID /本地身份验证以解锁某些内容,并且可以同时使用Touch ID和Passcode时,它只会显示" Enter Password" 首次尝试Touch ID失败后选项

是否可以立即显示?我设想一个未经过身份验证的用户在设备上使用Touch ID会尝试使用该应用,如果他们知道密码就可以使用它,并且他们可能不会尝试他们的指纹,因为他们知道它没有被添加。

1 个答案:

答案 0 :(得分:0)

是的,可以使用带密码的 Touch ID

  • 适用于 Apple Face ID(iPhone X、Xs、XR、XsMax)和其他配备 Touch ID 的设备。
  • 识别失败时的预定义错误处理。
  • 在多次失败尝试时使用设备密码自动进行身份验证。

使用 BiometricAuthentication 在您的应用中使用 Apple FaceID 或 TouchID 身份验证。它非常简单易用,可根据设备处理 Touch ID 和 Face ID 身份验证。

请检查这个例子:-

有两种选择

  • .deviceOwnerAuthenticationWithBiometrics

  • deviceOwnerAuthentication

    extension ViewController {
    
    func authenticationWithTouchID() {
     let localAuthenticationContext = LAContext()
     localAuthenticationContext.localizedFallbackTitle = "Use Passcode"
    
     var authError: NSError?
     let reasonString = "To access the secure data"
    
     if localAuthenticationContext.canEvaluatePolicy(.deviceOwnerAuthentication, error: &authError) {
    
         localAuthenticationContext.evaluatePolicy(.deviceOwnerAuthentication, localizedReason: reasonString) { success, evaluateError in
    
             if success {
                 print("User authenticated successfully")
                 //TODO: User authenticated successfully, take appropriate action
    
             } else {
                 //TODO: User did not authenticate successfully, look at error and take appropriate action
                 guard let error = evaluateError else {
                     return
                 }
    
                 print(self.evaluateAuthenticationPolicyMessageForLA(errorCode: error._code))
    
                 //TODO: If you have choosen the 'Fallback authentication mechanism selected' (LAError.userFallback). Handle gracefully
    
             }
         }
     } else {
    
         guard let error = authError else {
             return
         }
         //TODO: Show appropriate alert if biometry/TouchID/FaceID is lockout or not enrolled
         print(self.evaluateAuthenticationPolicyMessageForLA(errorCode: error.code))
     }
    }
    
    func evaluatePolicyFailErrorMessageForLA(errorCode: Int) -> String {
     var message = ""
     if #available(iOS 11.0, macOS 10.13, *) {
         switch errorCode {
             case LAError.biometryNotAvailable.rawValue:
                 message = "Authentication could not start because the device does not support biometric authentication."
    
             case LAError.biometryLockout.rawValue:
                 message = "Authentication could not continue because the user has been locked out of biometric authentication, due to failing authentication too many times."
    
             case LAError.biometryNotEnrolled.rawValue:
                 message = "Authentication could not start because the user has not enrolled in biometric authentication."
    
             default:
                 message = "Did not find error code on LAError object"
         }
     } else {
         switch errorCode {
             case LAError.touchIDLockout.rawValue:
                 message = "Too many failed attempts."
    
             case LAError.touchIDNotAvailable.rawValue:
                 message = "TouchID is not available on the device"
    
             case LAError.touchIDNotEnrolled.rawValue:
                 message = "TouchID is not enrolled on the device"
    
             default:
                 message = "Did not find error code on LAError object"
         }
     }
    
     return message;
    }
    
    func evaluateAuthenticationPolicyMessageForLA(errorCode: Int) -> String {
    
     var message = ""
    
     switch errorCode {
    
     case LAError.authenticationFailed.rawValue:
         message = "The user failed to provide valid credentials"
    
     case LAError.appCancel.rawValue:
         message = "Authentication was cancelled by application"
    
     case LAError.invalidContext.rawValue:
         message = "The context is invalid"
    
     case LAError.notInteractive.rawValue:
         message = "Not interactive"
    
     case LAError.passcodeNotSet.rawValue:
         message = "Passcode is not set on the device"
    
     case LAError.systemCancel.rawValue:
         message = "Authentication was cancelled by the system"
    
     case LAError.userCancel.rawValue:
         message = "The user did cancel"
    
     case LAError.userFallback.rawValue:
         message = "The user chose to use the fallback"
    
     default:
         message = evaluatePolicyFailErrorMessageForLA(errorCode: errorCode)
     }
    
     return message
     }
    }
    

Note:-Video converted to gif image. this example in passcode enter screen in keyboard not showing because it's recording.