Home>

touchid fingerprint unlock is now common in apps,In fact, this function is very simple to implement,Because Apple has already packaged it for us,Just implement a few methods.Let ’s take a look together.

Implementation process

1. First introduce the necessary header files for fingerprint unlock

#import<localauthentication/localauthentication.h>

2. Understand the two main 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, and a pop-up box will appear.

-(void) evaluatepolicy:(lapolicy) policy
  localizedreason:(nsstring *) localizedreason
     reply:(void (^) (bool success, nserror * __nullable error)) reply;

3. New lacontext object

Main property settings

localizedfallbacktitle :Used to set the name of the button on the left.The default is enter password.

localizedreason :Used to set prompts,Why use touch id

Unlock failed interface

//create lacontext
 lacontext * context=[lacontext new];
 //This attribute is the option to set the pop-up box after the fingerprint input fails
 context.localizedfallbacktitle [email protected]"No Forgotten Password";

4. The main callback method,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 (@ "Verification successfully refreshed the main interface");
   } else {
    nslog (@ "%@", error.localizeddescription);
    switch (error.code) {
     case laerrorsystemcancel:
     {
      nslog (@ "system deauthorized,If other apps cut in ");
      break;
     }
     case laerrorusercancel:
     {
      nslog (@ "User canceled verification touch id");
      break;
     }
     case laerrorauthenticationfailed:
     {
      nslog (@ "Authorization failed");
      break;
     }
     case laerrorpasscodenotset:
     {
      nslog (@ "The system has not set a password");
      break;
     }
     case laerrortouchidnotavailable:
     {
      nslog (@ "device touch id is not available, such as not open");
      break;
     }
     case laerrortouchidnotenrolled:
     {
      nslog (@ "device touch id is unavailable, user has 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 cases,Switch main thread processing ");
      }];
      break;
     }
    }
   }
  }];
 } else {
  nslog (@ "Does not support fingerprint recognition");
  switch (error.code) {
   case laerrortouchidnotenrolled:
   {
    nslog (@ "touchid is not enrolled");
    break;
   }
   case laerrorpasscodenotset:
   {
    nslog (@ "a passcode has not been set");
    break;
   }
   default:
   {
    nslog (@ "touchid not available");
    break;
   }
  }
  nslog (@ "%@", error.localizeddescription);
 }

to sum up

ios
  • Previous C # Windows API application based on FlashWindowEx method to achieve window flicker
  • Next java selenium operation browser instance