Analysis of IOS Development TouchID fingerprint unlocking function _ios

Source: Internet
Author: User

The effect chart is as follows

Implementation process

1. First introduce fingerprint to unlock the necessary header file

#import <LocalAuthentication/LocalAuthentication.h>

2. Understand the main two methods
This method is to determine whether the device supports TouchID.

-(BOOL) Canevaluatepolicy: (lapolicy) Policy error: (NSERROR * __autoreleasing *) Error __attribute__ ((Swift_error (none) ));

This is used to verify the TouchID, there will be pop-up box out.

-(void) EvaluatePolicy: (lapolicy) Policy
  Localizedreason: (NSString *) Localizedreason
     reply: (void (^) (BOOL Success, Nserror * __nullable error)) reply;

3. New Lacontext Object

Primary property settings

localizedFallbackTitle: Used to set the name of the button on the left, by default, enter Password.

localizedReason: Used to set the prompt to indicate why you want to use the touch ID


Unlock the Failed interface

 Create Lacontext
 lacontext *context = [Lacontext new];

 
 This property is the option to set the pop-up box after a failed fingerprint entry
 context.localizedfallbacktitle = @ "no forgotten password";

4. Main callback methods, including success and failure

Nserror *error = nil; if ([Context Canevaluatepolicy:lapolicydeviceownerauthenticationwithbiometrics Error:&error]) {NSLog (@ "Support fingerprint recognition")
  ); [Context evaluatepolicy:lapolicydeviceownerauthenticationwithbiometrics localizedreason:@ "fingerprint unlock" reply:^ (BOOL
   Success, Nserror * _nullable error) {if (success) {NSLog (@ "Verify successful refresh of main interface");
    }else{NSLog (@ "%@", error.localizeddescription);
      Switch (error.code) {case laerrorsystemcancel: {NSLog (@ "system cancellation, such as other app into");
     Break
      Case Laerrorusercancel: {NSLog (@ "User cancels authentication touch ID");
     Break
      Case laerrorauthenticationfailed: {NSLog (@ "Authorization failed");
     Break
      Case Laerrorpasscodenotset: {NSLog (@ "System does not set password");
     Break
      Case laerrortouchidnotavailable: {NSLog (@ "Device Touch ID not available, such as not open");
     Break
      Case laerrortouchidnotenrolled: {NSLog (@ "Device Touch ID not available, user not entered");
     Break Case LaerroruserfallbaCK: {[[Nsoperationqueue Mainqueue] addoperationwithblock:^{NSLog (@ "user chooses to enter password, switch main thread processing");
      }];
     Break
      } default: {[[Nsoperationqueue Mainqueue] addoperationwithblock:^{NSLog (@ "Other case, switch main thread processing");
      }];
     Break
 }
    }
   }
  }];
  }else{NSLog (@ "does not support fingerprint identification");
    Switch (error.code) {case laerrortouchidnotenrolled: {NSLog (@ "TouchID are not enrolled");
   Break
    Case Laerrorpasscodenotset: {NSLog (@ "A passcode has not been set");
   Break
    } default: {NSLog (@ "TouchID not available");
   Break
 } NSLog (@ "%@", error.localizeddescription); }

Summarize

Here, the fingerprint unlock function is almost complete, the use is really very simple, because the Apple has given us everything, it is easy for us developers. The tutorial is very simple to write, I hope you can forgive me, if you have any questions, please message exchange.

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.