great place to work

Demonstration of Touch ID – The Fingerprint Recognition Feature


Touch ID
In 2013, Apple introduced iPhone5s and also, the new fingerprint sensor on iPhone called TouchID. Being an iOS developer, I was quite excited about this, but my excitement was short lived when I learned that there were no APIs for it. With the release of iOS8, last year, Apple introduced a new framework so that the developers could use Touch ID. The Local Authentication framework helps developers to integrate their application with Touch ID.


This article demonstrates how you can integrate Touch ID with your application. Pre- requisite for the demonstration are Xcode 6 and an iPhone (iPhone 5s/6/6+) with TouchID.

The TouchID sensor, embedded on the home button of an iPhone, scans the finger print at 500 ppi resolution, to create the encrypted fingerprint data. While integrating Touch ID into your application, it is advised to consider the situations where the user cannot use his fingers as means to authenticate.  Let’s take an instance where, because of some hand injury, user is unable to use the Touch ID to authenticate it into the application. It is recommended that you have other means of authentication, in your application, such as a password or pin.

The heart of Local Authentication framework is LAContext class. You can use an instance of LAContext to check the security policy. This security policy check can happen only if the person using the TouchID is the owner of device. If the framework is unable to authenticate, it displays an error. Below are the lists of errors shown by the Local Authentication Framework:

  1. LAErrorAuthenticationFailed – Authentication was unsuccessful because the user failed to provide valid credentials.
  2. LAErrorUserCancel – Authentication was canceled by the user—for example, the user tapped Cancel in the dialog.
  3. LAErrorUserFallback – Authentication was canceled because the user tapped the fallback button (Enter Password).
  4. LAErrorSystemCancel – Authentication was canceled by system—for example, if another application came to foreground while the authentication dialog was up.
  5. LAErrorPasscodeNotSet – Authentication could not start because the passcode is not set on the device.
  6. LAErrorTouchIDNotAvailable – Authentication could not start because Touch ID is not available on the device.
  7. LAErrorTouchIDNotEnrolled – Authentication could not start because Touch ID has no enrolled fingers.

To try out Touch ID, let’s create a simple single view application.

  1. Let’s name it “TouchIDSampleApp”.


2. Open the main.  Storyboard and add a UIButton to the view of the ViewController. Let’s name the button as “Touch ID Login”

TouchID - Stage2

3.Now, define an action in ViewController.h file called useTouchID.

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

– (IBAction)useTouchID:(id)sender;


4. Go back to the main Storyboard and open the connection inspector of the UIButton. Connect the TouchUpInside event of the button to useTouchID action.

TouchID - Stage3

5. Go into ViewController.m file and import the below header.

#import <LocalAuthentication/LocalAuthentication.h>

6. Now, define the useTouchID method/action in ViewController.m

– (IBAction)useTouchID:(id)sender {
LAContext *context = [[LAContext alloc] init];

NSError *error = nil;
if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {
[context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
localizedReason:@”Are you the device owner?”
reply:^(BOOL success, NSError *error) {

if (error) {
UIAlertView *alertMessage = [[UIAlertView alloc] initWithTitle:@”Error”
message:@”Could not verify your identity.”
[alertMessage show];

if (success) {
UIAlertView * alertMessage = [[UIAlertView alloc] initWithTitle:@”Success”
message:@”Identity verified.”
[alertMessage show];

} else {
UIAlertView * alertMessage = [[UIAlertView alloc] initWithTitle:@”Error”
message:@”Identity verification failed.”
[alertMessage show];


} else {

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@”Error”
message:@”The device could not authenticate using TouchID.”
[alert show];


7. Now, you can build and run your application on a physical device and you will be prompted for Touch ID authentication, as below, when you click on Touch ID Login button.


This tutorial explains how you can integrate Touch ID in your app, using Local Authentication framework, available in iOS 8. Local Authentication framework does all the heavy lifting and user verification; and makes this implementation easy for developers.


Runi Kovoor,
Programmer Analyst & iOS development expert

Please Share Your Thoughts & Comments Below.

How can we help you?