Biometric Authentication
Authenticate users with Face ID and Touch ID.
Biometrics With LocalAuthentication
Face ID and Touch ID let users prove who they are without typing a password. The LocalAuthentication framework exposes this through LAContext, which evaluates an authentication policy and tells you whether the user passed.
import LocalAuthentication
let context = LAContext()
// One LAContext object drives a single auth attemptChecking Availability First
Always call canEvaluatePolicy before prompting. The device may lack biometric hardware, the user may not be enrolled, or biometrics may be locked out. This returns a Bool and an error explaining why if it fails.
import LocalAuthentication
func canUseBiometrics() -> Bool {
let context = LAContext()
var error: NSError?
return context.canEvaluatePolicy(
.deviceOwnerAuthenticationWithBiometrics,
error: &error)
}All lessons in this course
- Storing Secrets in the Keychain
- Keychain Access Control
- Biometric Authentication
- Data Protection and Encryption