Fingerprint Recognition, fingerprint recognition mobile phone

Source: Internet
Author: User

Fingerprint Recognition, fingerprint recognition mobile phone

Now, when both security and efficiency are required, ordinary passwords cannot meet our requirements, and fingerprint recognition is born.

Everyone has their own fingerprint. When you need to pay for the password, you only need to press it to avoid the tedious steps of entering the password, which is more secure, and Mom no longer has to worry about forgetting the password.

 

Now, let's get started with the question.

In fact, it is very easy to implement when we look at the Heights, because Apple has helped us encapsulate it, and we only need simple calls.

1. First, we need to import the header file:

#import <LocalAuthentication/LocalAuthentication.h>

2. Next, we need to determine whether our devices support fingerprint recognition (iPhone5s +, iOS8.0 +)

Next, you can determine whether the current user is the host or not. Is it so easy.

1-(IBAction) biologyAction :( id) sender {2 3 LAContext * context = [[LAContext alloc] init]; 4 NSError * error = nil; 5 NSString * reason = @ "we need to verify your fingerprint to confirm your identity"; 6 7 // determine whether the settings support fingerprint recognition (iPhone5s +, iOS8 +) 8 if ([context canEvaluatePolicy: LAPolicyDeviceOwnerAuthenticationWithBiometrics error: & error]) {9 10 // fingerprint recognition only checks whether the current user is the host 11 [context evaluatePolicy: Allow localizedReason: ^ (BOOL success, NSError * _ Nullable error) {12 if (success) {13 NSLog (@ "Fingerprint Authentication successful "); 14} 15 else {16 NSLog (@ "Fingerprint Authentication failed"); 17 NSLog (@ "error code: % zd", error. code); 18 NSLog (@ "error message: % @", error); 19 // error code error. code20 //-1: three consecutive fingerprint recognition errors 21 //-2: In the TouchID dialog box, click the cancel button 22 //-3: in the TouchID dialog box, click the Enter Password button 23 //-4: TouchID. the dialog box is canceled by the system, for example, pressing Home or power key 24 //-8: five consecutive fingerprint recognition errors, the TouchID function is locked. You need to enter the system password 25} 26}] Next time; 27} 28 else {29 NSLog (@ "TouchID device unavailable "); 30 NSLog (@ "error code: % zd", error. code); 31 NSLog (@ "error message: % @", error); 32} 33}

 

The code corresponding to Swift3.0 is posted below, so the principle is not mentioned. Just like above, the OC code is translated into Swift3.0.

1 import UIKit 2 import LocalAuthentication 3 4 class ViewController: UIViewController {5 6 override func viewDidLoad () {7 super. viewDidLoad () 8} 9 10 @ IBAction func yanzhengAction (_ sender: AnyObject) {11 12 let context = LAContext () 13 let reason = "we need your fingerprint to verify your identity" 14 var error: NSError? 15 16 if context. canEvaluatePolicy (LAPolicy. deviceOwnerAuthenticationWithBiometrics, error: & error) {17 context. evaluatePolicy (LAPolicy. deviceOwnerAuthenticationWithBiometrics, localizedReason: reason, reply: {(isSuc, error) in18 if isSuc {19 print ("Fingerprint Verification Successful ") 20} 21 else {22 print ("Fingerprint Verification Failed") 23 print ("error message: \ (error)") 24 // error code error. code25 //-1: three consecutive fingerprint recognition errors 26 //-2: Click the cancel button in the TouchID dialog box 27 //-3: In the TouchID dialog box Click the Enter Password button 28 //-4: TouchID dialog box is canceled by the system, for example, press Home or power key 29 //-8: five consecutive fingerprint recognition errors, the TouchID function is locked. The next time you need to enter the system password 30} 31}) 32} 33 else {34 print ("TouchID setting is not supported") 35 print ("error code: \ (error !. Code) ") 36 print (" error message: \ (error) ") 37} 38} 39}

 

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.