TundsAds
TundsAds

Reputation: 51

Authenticating the user with biometrics causing application to crash

So i'm following the books in terms of authenticating a user using biometrics. Below is some code i've wrote in a custom class called biometrics manager.

func authenticateUser(completion: @escaping (_ result: BiometricsStatus) -> Void) {

    DispatchQueue.main.async {

        guard self.deviceHasBiometricCapabilities() else { completion(.fail(error: .touchIDNotAvailable)); return }

        let authMethod = self.biometricType() == .faceID ? "Face ID" : "Touch ID"
        let loginMessage = "\(authMethod) to sign in"

        self.context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: loginMessage) { success, evaluateError in

            if success {
                completion(.success)
                return
            }

            if let error = evaluateError {
                completion(.fail(error: self.getBiometricsError(from: error)))
                return

            }
        }
    }
} 

I've debugged my application and it seems to be causing a crash on the evaluate policy line, i've enabled exception breakpoints to try and catch the crash but i'm receiving nothing at all in the console logs. The only thing that i seem to be getting in the console is the following.

Message from debugger: Terminated due to signal 9

Which isn't super helpful any possible pointers or ideas that may be causing this crash to occur at all?

Upvotes: 2

Views: 1671

Answers (1)

Ashley Mills
Ashley Mills

Reputation: 53121

You need to add the NSFaceIDUsageDescription key to your info.plist

From https://developer.apple.com/documentation/localauthentication/lacontext

Important

Include the NSFaceIDUsageDescription key in your app’s Info.plist file if your app allows biometric authentication. Otherwise, authorization requests may fail.

Upvotes: 4

Related Questions