Tech Blogs

perspectives for IT decision makers

Demonstration of Touch ID – The Fingerprint Recognition Feature

by (February 2, 2015)

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.

Demonstration

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”.

TouchID

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;

@end

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.”
delegate:nil
cancelButtonTitle:@”Ok”
otherButtonTitles:nil];
[alertMessage show];
return;
}

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

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

}];

} else {

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@”Error”
message:@”The device could not authenticate using TouchID.”
delegate:nil
cancelButtonTitle:@”Ok”
otherButtonTitles:nil];
[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.

Touch-stage4

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.

By,

Runi Kovoor,
Programmer Analyst & iOS development expert

Sorry no comment yet.

LEAVE A COMMENT

24/7 Toll Free(877)-643-1850(US)

Would you like to know more about us?

  • This field is for validation purposes and should be left unchanged.
Scroll Top