-2

How do I get a system access code? I want to block the controller in the application. I do not want the user to create a new code but I want to use the system code.

I saw that other applications have such feature

Example

1 Answers1

2

You can't get the users passcode, however you can authenticate a user and have them use their TouchID/FaceID

For this, you'll want to use the LocalAuthentication framework.

Here's an example:

let myContext = LAContext()
let myLocalizedReasonString = <#String explaining why app needs authentication#>

var authError: NSError?
if #available(iOS 8.0, macOS 10.12.1, *) {
    if myContext.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &authError) {
        myContext.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: myLocalizedReasonString) { success, evaluateError in
            if success {
                // User authenticated successfully, take appropriate action
            } else {
                // User did not authenticate successfully, look at error and take appropriate action
            }
        }
    } else {
        // Could not evaluate policy; look at authError and present an appropriate message to user
    }
} else {
    // Fallback on earlier versions
}

Credit: Apple

Will
  • 4,942
  • 2
  • 22
  • 47