Add Touch ID & Face ID in Swift

Sudhanshu Srivastava
2 min readDec 1, 2021
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

--

--

Sudhanshu Srivastava

I write about what I learn. Swift, Kotlin, Flutter, Social and Life.