0Pricing
Swift Academy · Lesson

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 attempt

Checking 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

  1. Storing Secrets in the Keychain
  2. Keychain Access Control
  3. Biometric Authentication
  4. Data Protection and Encryption
← Back to Swift Academy