Add Touch ID & Face ID in Swift

Photo by Tyler Lastovich on Unsplash

Authentication on iOS devices is really important. Let’s see how we can integrate a Touch ID & Face ID in our own application.

To integrate biometric authentication in your app first thing you need is LAContext

STEP 1: Create instance of LAContext

STEP 2: Check if current device has Biometric capability or not using following method

func canEvaluatePolicy(_ policy: LAPolicy, error: NSErrorPointer) -> Bool

STEP 3: If step 2 is true then you need to go ahead and ask for biometric input using below method

func evaluatePolicy(_ policy: LAPolicy, localizedReason: String) async throws -> Bool

STEP 4: Handling authenticationError depends on use case. Here are few simple most likely happened cases.

Please note that if your application is showing a Biometric alert and any other application interrupts (e.g. user drags down the notification centre drawer or a phone call came) it then it automatically dismisses with .systemCancel error.

Done, this are simple steps to integrate Biometric ID in your application.

Thanks for reading.
Cheers :-)

Complete code is here

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store