Punreach Rany
Punreach Rany

Reputation: 3690

Swift & deviceOwnerAuthentication : How to view passcode authentication board directly without going through Biometric Auth first?

I am trying to authenticate the user using the device passcode. And I want to view the passcode board directly. But with the code below, I always have to go through the biometric authentication first and fail in order to authenticate with a passcode. How do I get the passcode board directly?

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
                }
            }
            
            
            
            
        }
    }
    
}

Thank you

Upvotes: 0

Views: 1851

Answers (1)

Paulw11
Paulw11

Reputation: 114836

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.

Upvotes: 3

Related Questions