Swift3 TouchID获取错误类型';LAError';没有成员';用户取消';

Swift3 TouchID获取错误类型';LAError';没有成员';用户取消';,swift3,ios10,xcode8,Swift3,Ios10,Xcode8,我正在尝试启用touchId,但出现错误: 类型“LAError”没有成员“UserCancel” 我能发现它是LAError的成员,我遗漏了什么? 这就是Xcode给我的 类型“LAError”没有成员“AuthenticationFailed” 类型“LAError”没有成员“UserCancel” 类型“LAError”没有成员“UserFallback” 这是我的代码: func authenticateUser() { let context = LAContext()

我正在尝试启用touchId,但出现错误:

类型“LAError”没有成员“UserCancel”

我能发现它是
LAError
的成员,我遗漏了什么? 这就是Xcode给我的

类型“LAError”没有成员“AuthenticationFailed”
类型“LAError”没有成员“UserCancel”
类型“LAError”没有成员“UserFallback”

这是我的代码:

func authenticateUser()
{
    let context = LAContext()
    var error: NSError?
    let reasonString = "Authentication is needed to access your app! :)"

    if context.canEvaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, error: &error)
    {
        context.evaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, localizedReason: reasonString, reply: { (

            success, Error) -> Void in

            if success
            {
                print("Authentication successful! :) ")
            }
            else
            {
                    switch(error!._code)                 {
                case LAError.AuthenticationFailed.rawValue:
                    print("Authentication was cancelled by the system.")
                case LAError.UserCancel.rawValue:
                    print("Authentication was cancelled by the user.")

                case LAError.UserFallback.rawValue:
                    print("User selected to enter password.")
                    OperationQueue.main.addOperation({ () -> Void in
                        self.showPasswordAlert()
                    })
                default:
                    print("Authentication failed! :(")
                    OperationQueue.main.addOperation({ () -> Void in
                        self.showPasswordAlert()
                    })
                }
            }

        })
    }
    else
    {
        print(error?.localizedDescription)
        OperationQueue.main.addOperation({ () -> Void in
            self.showPasswordAlert()
        })
    }
}

// MARK: Password Alert

func showPasswordAlert()
{
    let alertController = UIAlertController(title: "Touch ID Password", message: "Please enter your password.", preferredStyle: .alert)

    let defaultAction = UIAlertAction(title: "OK", style: .cancel) { (action) -> Void in

        if let textField = alertController.textFields?.first as UITextField?
        {
            if textField.text == "veasoftware"
            {
                print("Authentication successful! :) ")
            }
            else
            {
                self.showPasswordAlert()
            }
        }
    }
    alertController.addAction(defaultAction)

    alertController.addTextField { (textField) -> Void in

        textField.placeholder = "Password"
        //textField.secureTextEntry = true

    }
    self.present(alertController, animated: true, completion: nil)
}
Swift

这是我的解决办法

import UIKit
import LocalAuthentication

func authendicateTouchID() {
        let context: LAContext = LAContext()
        let myLocalizedReasonString = "Authentication is needed to access your Home ViewController."

        var authError: NSError?
        if context.canEvaluatePolicy(.deviceOwnerAuthentication, error: &authError) {
            context.evaluatePolicy(.deviceOwnerAuthentication, localizedReason: myLocalizedReasonString, reply: { success, error in
                if success {
                    DispatchQueue.main.async {
                    print("Authentication success by the system")
                    }
                }
                else {
                    if let error = error {
                        let message = self.showErrorMessageForLAErrorCode(errorCode: error as! Int)
                    print(message)
                    }
                }

            })
        }
    }

    func showErrorMessageForLAErrorCode( errorCode:Int ) -> String{

        var message = ""

        switch errorCode {

        case LAError.appCancel.rawValue:
            message = "Authentication was cancelled by application"

        case LAError.authenticationFailed.rawValue:
            message = "The user failed to provide valid credentials"

        case LAError.invalidContext.rawValue:
            message = "The context is invalid"

        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.touchIDLockout.rawValue:
            message = "Too many failed attempts."

        case LAError.touchIDNotAvailable.rawValue:
            message = "TouchID is not available on the device"

        case LAError.userCancel.rawValue:
            message = "The user did cancel"

        case LAError.userFallback.rawValue:
            message = "The user chose to use the fallback"

        default:
            message = "Did not find error code on LAError object"

        }

        return message

    }

    @IBAction func buttonFingerPrint(_ sender: Any) {
        self.authendicateTouchID()
    }

您查过文档了吗?根据,错误代码以小写字母开头…非常感谢