Using Biometrics on iOS
I recently had to dig into biometrics on iOS and thought I would write some things down, mainly for the benefit of Future Me.
Process
Apple’s documentation has a good walkthrough of how to use biometrics to authenticate a user in your app. The process boils down to:
- Add
NSFaceIDUsageDescription
to your app’sInfo.plist
. This string is shown the first time your app attempts to use Face ID. If you don’t include it, your app will crash at this point. - Create a
LAContext
object. See the note below about the expected lifetime of this object. - Check what functionality is available on the device. You do this by calling
canEvaluatePolicy(_:error:)
on theLAContext
and passing the desiredLAPolicy
. - Once you have called
canEvaluatePolicy(_:error:)
,biometryType
is populated on theLAContext
which indicates what biometrics are supported on the device. You can use this to update your UI (e.g. show...