How to use Face ID to authenticate users

UISwift Team Avatar

·

·

Face ID offers a secure and convenient method for users to authenticate themselves using facial recognition. Just like Touch ID, Face ID leverages the biometric information registered on the device. Importantly, your app cannot access these facial data directly, ensuring privacy and security.

Prerequisites

Before getting started, you need to import the LocalAuthentication framework:

When using Face ID, there are several potential outcomes you need to handle:

• The device may not support Face ID.

• The device supports Face_ID, but it has not been configured by the user.

• The user fails authentication, perhaps due to misalignment or choosing a different authentication method, like a passcode.

Remember, Apple mandates that apps provide an alternative authentication method in case Face_ID is unavailable or fails, like a passcode entry.

The core part of using Face_ID authentication looks like this:

This function performs the following:

• Checks if Face_ID is available and configured on the device.

• Prompts the user to authenticate using Face_ID.

• Handles both successful and failed authentication attempts.

You can further customize the action inside runSecureAction() and show appropriate error messages based on the failure scenario.