0

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

Punreach Rany
  • 2,560
  • 7
  • 23
  • 56
  • Check here: https://developer.apple.com/documentation/localauthentication/lapolicy/deviceownerauthentication It says ... `If biometry is available, enrolled, and not disabled, the system uses that first`... – LoVo Apr 14 '21 at 08:35
  • I found and tried this method below. It kinda worked but I have no clue what these code do. https://stackoverflow.com/questions/46723662/is-it-possible-to-authenticate-using-only-the-passcode-even-device-has-touch-id – Punreach Rany Apr 15 '21 at 00:05

1 Answers1

2

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.

Paulw11
  • 108,386
  • 14
  • 159
  • 186
  • I found and tried this method below. It kinda worked but I have no clue what these code do. https://stackoverflow.com/questions/46723662/is-it-possible-to-authenticate-using-only-the-passcode-even-device-has-touch-id – Punreach Rany Apr 15 '21 at 00:05
  • That code puts an object in the keychain and retrieves set, setting the "require passcode" policy. It is slightly different to simple local authentication. – Paulw11 Apr 15 '21 at 00:32