Face ID and Touch ID Biometric Authentication

Add additional security to your iOS app

In this Swift tutorial, I will be explaining how you can add Face ID and Touch ID Authentication for securing your user's data. As you already know, the Face ID technology was introduced together with the release of iPhone X, and Touch ID came with the iPhone 5s and is still available in the latest iPhone 8.

LocalAuthentication

The LocalAuthentication framework enables us to request authentication from users through passphrases or biometrics. Because you can't have both Face ID and Touch ID on a single device, Apple has kept everything under one simple method.

All you need to do is import LocalAuthentication and then copy the following code where you need it.

As I have mentioned earlier, the canEvaluatePolicy method will detect the biometrics support on the device, and present the correct Authentication feature. This kind of authentication is mostly wanted for apps that contain payments features, files storage, finances and any other kind of sensitive data.

Testing on iOS Simulator

If you have wondered how to test this feature if you don't have a physical device such as the iPhone X or iPhone 5s and later, don't worry. The iOS Simulator provides us with a feature that can bypass this kind of behavior.

Click on your Simulator and then go Hardware -> Touch ID or FaceID from the top menu bar.

In the submenu there will be 3 options available:

  1. Enrolled - enables the Touch ID or Face ID feature
  2. Matching Touch - successful authentication
  3. Non-matching Touch - authentication failed