This article, created by Mayank Birani, the author of Learning iOS 8 for Enterprise, Apple introduced a new feature in iOS 7 called Touch ID authentication. Previously, there was only four-digit passcode security in iPhones; now, Apple has extended security and introduced a new security pattern in iPhones. In Touch ID authentication, our fingerprint acts as a password. After launching the Touch ID fingerprint-recognition technology in the iPhone 5S last year, Apple is now providing it for developers with iOS 8. Now, third-party apps will be able to use Touch ID for authentication in the new iPhone and iPad OSes. Accounting apps, and other apps that contain personal and important data, will be protected with Touch ID. Now, you can protect all your apps with your fingerprint password.
(For more resources related to this topic, see here.)
There are two ways to use Touch ID as an authentication mechanism in our iOS 8 applications. They are explained in the following sections.
The Local Authentication API is an API that returns a Boolean value to accept and decline the fingerprint. If there is an error, then an error code gets executed and tells us what the issue is.
Certain conditions have to be met when using Local Authentication. They are as follows:
Keychain Access includes the new Touch ID integration in iOS 8. In Keychain Access, we don't have to work on implementation details; it automatically handles the passcode implementation using the user's passcode. Several keychain items can be chosen to use Touch ID to unlock the item when requested in code through the use of the new Access Control Lists (ACLs). ACL is a feature of iOS 8. If Touch ID has been locked out, then it will allow the user to enter the device's passcode to proceed without any interruption.
There are some features of Keychain Access that make it the best option for us. They are listed here:
Apple provides a framework to use Touch ID in our app called Local Authentication. This framework was introduced for iOS 8. To make an app, including the Touch ID authentication, we need to import this framework in our code. It is present in the framework library of Apple. Let's see how to use the Local Authentication framework:
#import<localAuthentication/localAuthentication.h>
This framework will work on Xcode 6 and above.
LAContext *passcode = [[LAContext alloc] init];
- (BOOL)canEvaluatePolicy:(LAPolicy)policy error:
(NSError * __autoreleasing *)error;
- (void)evaluatePolicy:(LAPolicy)policy localizedReason: (NSString *)localizedReason reply:(void(^)(BOOL success, NSError *error))reply;
LAContext *passcode = [[LAContext alloc] init]; NSError *error = nil; NSString *Reason =
<#String explaining why our app needs authentication#>; if ([passcode canEvaluatePolicy:
LAPolicyDeviceOwnerAuthenticationWithBiometrics
error:&error]) { [passcode evaluatePolicy:
LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:Reason reply:^(BOOL success, NSError
*error) { if (success) { // User authenticated successfully } else { // User did not authenticate successfully,
go through the error } }]; } else { // could not go through policy look at error and show
an appropriate message to user }
In this article, we focused on the Touch ID API, which was introduced in iOS 8. We also discussed how Apple has improved its security feature using this API.
Further resources on this subject: