Prompt
How do I support biometric sign-in with Face ID or Touch ID for my app?
Latest observation
Oct 28, 2026
OpenAI APIWeb search: off
To support biometric sign-in with Face ID or Touch ID on iOS, use LocalAuthentication. The basic flow is:
- Check whether biometrics are available on the device.
- Ask the system to authenticate the user.
- If successful, unlock your app or sign the user in.
1) Add the framework
Import LocalAuthentication:
import LocalAuthentication
2) Ask the system to authenticate
Use LAContext and evaluatePolicy:
import LocalAuthentication
func authenticateUser(completion: @escaping (Bool, Error?) -> Void) {
let context = LAContext()
var error: NSError?
let reason = "Sign in to your account"
if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) {
context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics,
localizedReason: reason) { success, authError in
DispatchQueue.main.async {
completion(success, authError)
}
}
} else {
DispatchQueue.main.async {
completion(false, error)
}
}
}
3) Handle results
- Success: proceed with sign-in or unlock secure content.
- Failure: show fallback UI (password, passcode, etc.).
Example usage:
authenticateUser { success, error in
if success {
// Unlock app / continue sign-in
print("Authenticated")
} else {
// Show error or fallback login
print("Authentication failed: \(String(describing: error))")
}
}
4) Add Face ID usage description
If you support Face ID, you must include this key in your app’s Info.plist:
<key>NSFaceIDUsageDescription</key>
<string>We use Face ID to securely sign you in.</string>
Without this, Face ID authentication will fail.
5) Consider fallback to passcode
If you want the user to be able to authenticate with device passcode as a fallback, use:
context.canEvaluatePolicy(.deviceOwnerAuthentication, error: &error)
and:
context.evaluatePolicy(.deviceOwnerAuthentication,
localizedReason: reason) { success, authError in
...
}
This allows biometric auth or device passcode if biometrics aren’t available or fail.
6) Recommended practices
- Never store passwords in plain text.
- Use biometrics to unlock a token, key, or session stored securely in the Keychain.
- Treat biometric auth as a way to unlock existing credentials, not a replacement for your auth backend.
- Always provide a fallback sign-in method.
7) Example: unlocking a Keychain item
A common pattern is:
- Store an auth token in Keychain.
- Mark it so access requires biometrics.
- Use biometrics to retrieve the token when the user signs in.
If you want, I can also show:
- a SwiftUI example
- a UIKit example
- how to store/retrieve a token from Keychain with biometrics