IOS fingerprint unlock verification TouchID, iostouchid
IOS fingerprint unlocking
1. First, introduce the dependency framework LocalAuthentication. framework
#import <LocalAuthentication/LocalAuthentication.h>
2. Then, determine whether the system is iOS8 or above.
// Only after iOS8.0 is supported can the fingerprint recognition interface if ([UIDevice currentDevice]. systemVersion. floatValue <8.0) {return ;}
3. At last, you can call the following method when the APP is started to integrate all features of fingerprint unlocking.
-(Void) evaluateAuthenticate {// create LAContext * context = [[LAContext alloc] init]; NSError * error = nil; NSString * result = @ "verify the existing fingerprint "; // first, use canEvaluatePolicy to determine the status of the device. if ([context canEvaluatePolicy: condition error: & error]) {// supports fingerprint verification. [context evaluatePolicy: Condition localizedReason: result reply: ^ (BOOL success, NSError * error) {if (success) {// Verification Successful, main thread processing UI} else {NSLog (@ "% @", error. localizedDescription); switch (error. code) {case LAErrorSystemCancel: {// The system cancels the authorization. For example, if other apps switch to break;} case LAErrorUserCancel: {// The user cancels the verification Touch ID break;} case LAErrorAuthenticationFailed: {// break failed to be authorized;} case LAErrorPasscodeNotSet: {// The password break is not set in the system;} case LAErrorTouchIDNotAvailable: {// The device Touch ID is unavailable, for example, break is not enabled ;} case LAErrorTouchIDNotEnrolled: {// The device Touch ID is unavailable and break is not input;} case LAErrorUserFallback: {[[NSOperationQueue mainQueue] addOperationWithBlock: ^ {// The user selects the input password, switch master thread processing}]; break;} default: {[[NSOperationQueue mainQueue] addOperationWithBlock: ^ {// in other cases, Switch master thread processing}]; break ;}}}] ;}else {// fingerprint identification is not supported, and NSLog (@ "fingerprint identification not supported") is used to output error details; 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 );}}