How to integrate the Touch ID feature in IOS 8

Source: Internet
Author: User

How to integrate the Touch ID feature in IOS 8

In September 2013, Apple was equipped with a range of hardware upgrades for the latest iphone products that were released. The most innovative mechanism in the iphone 5s is undoubtedly the ultra-thin metal ring designed around the home button, the fingerprint sensor called Touch ID. Developers then began to take their API as a breakthrough, hoping to introduce this latest feature in their own applications. Now a year has passed, the new framework provided by IOS 8 has made it easier for developers to use the fingerprint sensing device.

This local authentication framework makes it easy to implement user authentication, which you can use to complete the application's login mechanism or to protect sensitive data in your application. In today's tutorial, we'll work together on how to apply the entire set of options to our design results, what data we can get from the device, and step-by-step guide you through building a sample application.

To complete this tutorial, you'll need to install Xcode 6 to create a new project, and you'll need a device with Touch ID to test the sample app you've created.

1. Touch ID

Touch ID refers to the fingerprint sensor that is installed in the iphone 5s home button. Its presence is designed to help users complete the identification process more easily, thereby encouraging the user to use the protection mechanism as much as possible. You can configure up to five fingerprint identification information on each device. So far, Touch ID has been used to unlock devices and complete purchases in the itunes Store, App store, and ibooks store. Before we further explore how to introduce it to our own applications, we need to understand the sensor itself first.

The Touch ID sensor scans the user's fingerprint at a resolution of 500 pixels per inch and classifies the fingerprint pattern into one of three types: arch, vortex, and ring. This sensor is designed with the convenience in mind, and you can scan your fingers from any angle and the current scan results can match the original fingerprint record in any direction correctly.

Apple claims that the chance of any given fingerprint pattern, Touch ID error is only one out of 10,000, the protection effect is significantly better than the original four-digit PIN mechanism-after all, its content can only be 0001 to 9999 to provide 10,000 combinations of possibilities. However, Apple does not clearly point out that in some cases we may not be able to use our own fingerprint to achieve a smooth unlock operation, for example, after swimming, the finger texture folds change.

If you're going to use touch ID, the most important thing is to take into account the usage scenarios where users might not be able to use their fingers for validation. Since Apple no longer allows us to use the PIN code verification mechanism that comes with the device, if the Touch ID doesn't work, it's best to create an additional set of password matching schemes within the application.

2. Safety precautions

The biggest problem with the instruction sensor is that the user's privacy is fundamentally violated. If everyone's password content is leaked, then you can completely modify the timely rescue, malicious people simply cannot continue to use its access to the user's sensitive data. However, if everyone's fingerprint information, or Apple's fingerprint content algorithm has been leaked, we obviously have no way to quickly change it.

The Local authentication Framework is responsible for handling all user authentication tasks. When combined with Touch ID, it is important to ensure that the framework does not reveal any user-related details and that no data is transferred from the device. However, developers can use this framework to check whether a particular user is allowed to use the corresponding application.

If you are already familiar with the OAuth specification, you will find that these two validation methods are actually quite similar. We require a third party to review the identity of the user, and if we trust the third party fully, we may provide the user with the certification credentials directly based on their feedback.

3. Lacontext

The core of the Local authentication Framework is the Lacontext class. Developers can use Lacontext instances to evaluate security policies. As of this time, this is the only management strategy that can be used. It uses the Touch ID sensor to check whether the user's identity is the device holder. Other security management strategies may be introduced in the future. For example, Apple may introduce a class of unlicensed roles that allow access only to specific resources.

If the framework does not complete validation, an error message is provided. The reasons why the device cannot complete the validation may include the following:

    • The laerrortouchidnotavailable device itself does not have a fingerprint sensing device.
    • The Laerrorpasscodenotset device does not have password settings information, which means that the Touch ID feature is disabled.
    • The laerrortouchidnotenrolled has been set up with a password mechanism, but no fingerprint content has been stored in the device configuration.

If you encounter the error message that contains the above error code, you will need to use some other methods to complete the user authentication. In this case, you can't rely on Touch ID alone to complete the protection.

Let's create a sample application together to learn how to use the local authentication framework.

4. First step of Project Setup

Open Xcode and choose New > Project ... from the File menu. Next, select the single view application application in the list of iOS application templates and click Next.

Step Two

To enter a name for our project, I call my app named Auth. Next enter the organization name, company ID, and class prefix. Select iphone in the Devices list, then click Next, then select a file save location for the project.

Step Three

Click ViewController.h and define a new operation, authenticatebuttontapped, which triggers the entire validation process. The interface appearance of the Viewcontroller class should look like this:

    1. #import <UIKit/UIKit.h>
    2. @interface Viewcontroller:uiviewcontroller
    3. -(Ibaction) authenticatebuttontapped: (ID) sender;
    4. @end
Fourth Step

Open the Main.storyboard and drag a button to the view of the controller. Change the label of the button so that it reads as authneticate.

Fifth Step

Right-click the button to display the Connections Inspector. Click the plus sign to the left of the touch up inside event and select the view controller that holds the button. A new menu will be displayed on the screen and you will need to select the actions we have already set up here.

5. Verifying the user's identity the first step

Turn on VIEWCONTROLLER.M to activate the Authenticatebuttontapped method. Add the following import statements for the local authentication framework at the beginning of the file.

    1. #import <LocalAuthentication/LocalAuthentication.h>
Step Two

In the Authenticatebuttontapped method, we create a set of background information and detect whether the background is able to evaluate the lapolicydeviceownerauthenticationwithbiometrics strategy, If different, an error message is displayed.

  1. -(Ibaction) authenticatebuttontapped: (ID) Sender {
  2. Lacontext *context = [[Lacontext alloc] init];
  3. Nserror *error = nil;
  4. if ([Context Canevaluatepolicy:lapolicydeviceownerauthenticationwithbiometrics Error:&error]) {
  5. //Authenticate User
  6. } Else {
  7. Uialertview *alert = [[Uialertview alloc] initwithtitle:@"Error"
  8. message:@"Your device cannot authenticate using TouchID."
  9. Delegate:nil
  10. cancelbuttontitle:@"OK"
  11. Otherbuttontitles:nil];
  12. [Alert show];
  13. }
  14. }
Step Three

If the Lacontext object is able to authenticate with Touch ID, then we can review the identity of the user. If there is no error message, we can tell if the current user belongs to the device holder. Finally, implement the Authenticatebuttontapped method with the following code.

  1. -(void) authenicatebuttontapped: (ID) Sender {
  2. Lacontext *context = [[Lacontext alloc] init];
  3. Nserror *error = nil;
  4. if ([Context Canevaluatepolicy:lapolicydeviceownerauthenticationwithbiometrics Error:&error]) {
  5. [Context Evaluatepolicy:lapolicydeviceownerauthenticationwithbiometrics
  6. localizedreason:@"is you the device owner?"
  7. reply:^ (BOOL success, Nserror *error) {
  8. if (error) {
  9. Uialertview *alert = [[Uialertview alloc] initwithtitle:@"Error"
  10. message:@"There was a problem verifying your identity."
  11. Delegate:nil
  12. cancelbuttontitle:@"OK"
  13. Otherbuttontitles:nil];
  14. [Alert show];
  15. return;
  16. }
  17. if (success) {
  18. Uialertview *alert = [[Uialertview alloc] initwithtitle:@"Success"
  19. message:@ "You are thedevice owner!"
  20. Delegate:nil
  21. cancelbuttontitle:@"OK"
  22. Otherbuttontitles:nil];
  23. [Alert show];
  24. } Else {
  25. Uialertview *alert = [[Uialertview alloc] initwithtitle:@"Error"
  26. message:@ "You aren't thedevice owner."
  27. Delegate:nil
  28. cancelbuttontitle:@"OK"
  29. Otherbuttontitles:nil];
  30. [Alert show];
  31. }
  32. }];
  33. } Else {
  34. Uialertview *alert = [[Uialertview alloc] initwithtitle:@"Error"
  35. message:@"Your device cannot authenticate using TouchID."
  36. Delegate:nil
  37. cancelbuttontitle:@"OK"
  38. Otherbuttontitles:nil];
  39. [Alert show];
  40. }
  41. }
6. Build and run

Below we need to build and run the app on a physical device equipped with a fingerprint sensor and authenticate by tapping the home button. As long as your device is able to support the Touch ID feature, the authentication mechanism in the application should be passed correctly. When you place your finger on the sensor, the application can correctly identify whether the user belongs to the legitimate holder of the device.

Summarize

In today's tutorial, we learned that iOS 8 has recently joined the local authentication framework. By checking the identity of the user, the Lacontext class allows the user to complete the identification work without providing any sensitive data directly to the application itself.

English original link: IOS 8:integrating Touch ID

How to integrate the Touch ID feature in IOS 8

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.