I've implemented Face ID in my app to authenticate after the user is authenticated, so they don't have to sign in again to log into their account. However, it asks me to enter my iPhone's passcode instead of scanning my face. Is there any way to fix this? Is there something I have to add?
Face ID Authentication Enabled, But Prompting User to Enter Password Instead
It’s hard to say what’s going on here without knowing what API you’re using, and how you’re using it. There are multiple ways to access biometric authentication, including:
-
Using a keychain item that’s protected with biometrics
-
Using
LAContext
directly -
Using the
LARight
API we added in iOS 16 (see WWDC 2022 Session 10108 Streamline local authorization flows)
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
I am using LAContext.
if let user = Auth.auth().currentUser {
let context = LAContext()
var error: NSError?
guard context.canEvaluatePolicy(.deviceOwnerAuthentication, error: &error) else {
print(error?.localizedDescription ?? "Can't evaluate policy")
return
}
Task {
do {
try await context.evaluatePolicy(.deviceOwnerAuthentication, localizedReason: "Use \(context.biometryType == .faceID ? "Face ID":"Touch ID") to log into your account")
viewModel.getUser(docId: user.uid) { result in
switch result {
case .success(let userProfile):
habitat.user = userProfile
habitat.appScene = .home
case .failure(let error):
viewModel.authError = error
viewModel.isError = true
}
}
} catch let error {
print(error.localizedDescription)
}
}
}