Use TouchID verification and ios8touchid verification in ios8.

Source: Internet
Author: User

Use TouchID verification and ios8touchid verification in ios8.

In iOS8, developers can use APIs that open the Touch ID permission to third-party applications so that they can use Fingerprint Authentication in applications to complete user authentication.

This document describes how to integrate data into an application.Touch IDTo verify the user's identity.

#import <LocalAuthentication/LocalAuthentication.h>This library must be Xcode6 connected to a real machine and will not prompt for an error that cannot be found. If it is a simulator, the system will prompt that the library cannot be found.

 

1-(IBAction) authenticateButtonTapped :( id) sender {2 LAContext * context = [[LAContext alloc] init]; 3 context. localizedFallbackTitle = @ "Enter Password"; 4 NSError * error = nil; 5 6 if ([context canEvaluatePolicy: condition error: & error]) {7 8 [context evaluatePolicy: LAPolicyDeviceOwnerAuthenticationWithBiometrics 9 localizedReason: @ "Are you the owner of this device? "10 reply: ^ (BOOL success, NSError * error) {11 if (success) {12 dispatch_async (dispatch_get_main_queue (), ^ {13 14 UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @ "Success" 15 message: @ "you are the device owner. "16 delegate: nil 17 cancelButtonTitle: @" OK "18 otherButtonTitles: nil]; 19 [alert show]; 20 }); 21 22} else {23 24 25/* 26 // the user does not provide a valid certificate (3 chances failed-authentication failed ). 27 LAErrorAuthenticationFailed = kLAErrorAuthenticationFailed, 28 29 // The authentication is canceled (the user clicks the cancel button ). 30 LAErrorUserCancel = kLAErrorUserCancel, 31 32 // The authentication is canceled. Click the back button (enter the password ). 33 LAErrorUserFallback = kLAErrorUserFallback, 34 35 // The authentication is canceled by the system (for example, another application goes to the front-end ). 36 LAErrorSystemCancel = kLAErrorSystemCancel, 37 38 // authentication fails because the password is not set on the device. 39 LAErrorPasscodeNotSet = kLAErrorPasscodeNotSet, 40 41 // authentication fails because the Touch ID is unavailable on the device. 42 LAErrorTouchIDNotAvailable = kLAErrorTouchIDNotAvailable, 43 44 // identity verification cannot be started because there is no registered finger Touch ID. If no fingerprint password is set. 45 LAErrorTouchIDNotEnrolled = kLAErrorTouchIDNotEnrolled, 46 **/47 switch (error. code) {48 case LAErrorAuthenticationFailed: 49 NSLog (@ "authentication failed. "); 50 51 break; 52 53 case LAErrorUserCancel: 54 NSLog (@" the user clicks the cancel button. "); 55 56 break; 57 58 case LAErrorUserFallback: 59 NSLog (@" the user clicks to enter the password. "); 60 61 break; 62 63 case LAErrorSystemCancel: 64 NSLog (@" another application goes to the foreground "); 65 66 break; 67 68 case LAErrorPasscodeNotSet: 69 NSLog (@ "the password is not set on the device"); 70 71 break; 72 73 case LAErrorTouchIDNotAvailable: 74 NSLog (@ "The Touch ID is unavailable on the device "); 75 76 break; 77 78 case LAErrorTouchIDNotEnrolled: 79 NSLog (@ "unregistered finger Touch ID. "); 80 81 break; 82 83 default: 84 NSLog (@" Touch ID not configured "); 85 86 break; 87} 88} 89}]; 90 91} else {92 dispatch_async (dispatch_get_main_queue (), ^ {93 94 UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @ "error message" 95 message: @ "your device does not have a Touch ID. "96 delegate: nil 97 cancelButtonTitle: @" OK "98 otherButtonTitles: nil]; 99 [alert show]; 100}); 101} 102 103}

Where:

(1) localizedFallbackTitle: used to set the name of the button on the left. The default value isEnter the password.

(2) localizedReason: used to set the prompt, indicating why Touch ID is used, such as @ "Are you the owner of the device? ".

The official API is simple, just a few words.

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.