0

我正在尝试使用设备密码对用户进行身份验证。我想直接查看密码板。但是使用下面的代码,我总是必须先通过生物特征认证并且失败才能使用密码进行认证。如何直接获取密码板?

import UIKit
import LocalAuthentication

class ViewController: UIViewController {

    @IBOutlet weak var userButton: UIButton!
    
    @IBOutlet weak var resultLabel: UILabel!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
    }

    @IBAction func buttonPressed(_ sender: UIButton) {
        authenticateUser()
    }
    
    func authenticateUser() {
        let context = LAContext()
        
        context.evaluatePolicy(LAPolicy.deviceOwnerAuthentication, localizedReason: "Please authenticate to proceed.") { (success, error) in
            DispatchQueue.main.async {
                if success {
                    self.resultLabel.text = "Success"
                    print("Success")
                }else{
                    self.resultLabel.text = "Failed"
                    print("Failed")
                    return
                }
            }
            
            
            
            
        }
    }
    
}

谢谢

4

1 回答 1

1

Local authentication with passcode only is not available if the device has biometric capability and the user has enrolled.

You can prevent the fallback to passcode by using LAPolicy.deviceOwnerAuthenticationWithBiometrics but there is no policy that goes directly to the passcode option.

LAPolicy.deviceOwnerAuthentication will always try biometric first, if it is available, before falling back to device passcode.

于 2021-04-14T10:33:47.820 回答