IOS Fingerprint identification detailed and example code _ios

Source: Internet
Author: User
Tags error code

IOS fingerprint identification, here to organize the knowledge used in the project.

IOS fingerprint recognition now, in the demand for security and efficiency, the common password can not meet our requirements, fingerprint recognition was born.

Everyone has their own fingerprint, in need of payment, such as input password, we simply click to avoid the cumbersome steps to enter the password, more secure, and mom no longer have to worry about our forgotten password.

In fact, listening to tall, to achieve a very simple, because the Apple has helped us to encapsulate the good, we need to simply call it.

1, first, we need to import the header file:

#import <LocalAuthentication/LocalAuthentication.h>

2. Next, we need to determine if our device supports fingerprint identification (iphone5s+,ios8.0+)

Next, determine whether the current user is the owner can be, finished, is not so easy ah.

-(Ibaction) Biologyaction: (ID) Sender {lacontext *context = [[Lacontext alloc] init];
  Nserror *error = nil;
  
  NSString *reason = @ "We need to verify your fingerprint to confirm your identity"; Determines whether the settings support fingerprint recognition (iphone5s+, ios8+ Support) if ([Context Canevaluatepolicy:lapolicydeviceownerauthenticationwithbiometrics Error:&error]) {//Fingerprint recognition only determines whether the current user is the main computer [context Evaluatepolicy:lapolicydeviceownerauthenticationwithbiometri
      CS Localizedreason:reason reply:^ (BOOL success, Nserror * _nullable error) {if (success) {NSLog (@ "Successful fingerprint Authentication");
        } else{NSLog (@ "Fingerprint authentication failed");
        NSLog (@ "error code:%ZD", Error.code);
        NSLog (@ "error message:%@", error);
        Error code Error.code//-1: Three consecutive fingerprint identification errors//2: Click the Cancel button in the TouchID dialog box//3: Click the Enter Password button in the TouchID dialog
  The -4:touchid dialog box is canceled by the system, such as pressing home or power button//-8: Five consecutive fingerprint identification errors, TouchID function is locked, the next need to enter the system password}};
    } else{NSLog (@ "TouchID device not available");
    NSLog (@ "error code:%ZD", Error.code);
  NSLog (@ "error message:%@", error); }
}

Below the Swift3.0 version of the corresponding code, the principle does not say, and above, just the OC code translated into a Swift3.0 version.

Import Uikit Import Localauthentication class Viewcontroller:uiviewcontroller {override Func Viewdidload () { Super.viewdidload ()} @IBAction func Yanzhengaction (_ Sender:anyobject) {Let context = Lacontext () l
    
    Et reason = "We need your fingerprint to verify your identity" var error:nserror?
      If Context.canevaluatepolicy (Lapolicy.deviceownerauthenticationwithbiometrics, Error:&error) { Context.evaluatepolicy (Lapolicy.deviceownerauthenticationwithbiometrics, Localizedreason:reason, reply: {ISSUC, Error) in If issuc{print ("Successful fingerprint Verification")} else{Print ("Fingerprint verification Failed") print ("wrong False message: \ (Error) ")//Error code Error.code//-1: Three consecutive fingerprint identification error//2: In the TouchID dialog box, click the Cancel button//- 3: In the TouchID dialog box clicked the input Password// -4:touchid dialog box was canceled by the system, such as pressing home or power button//-8: Five consecutive fingerprint identification errors, TouchID function is locked, the next need to enter the system Password}}) else{print ("TouchID settings does not support") Print (Error code: \ error!. Code) "PRINT (Error message: \ (Errors)}}} 

Thank you for reading, I hope to help you, thank you for your support for this site!

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.