IOS Touch ID and iostouchid
1. First import the header file
#import <LocalAuthentication/LocalAuthentication.h>
2. Key code
-(Void) validateTouchID {LAContext * context = [[LAContext alloc] init]; NSError * error; NSString * tip = @ "verify existing mobile phone fingerprints by using the Home Key "; // determine whether the mobile phone has a fingerprint if ([context canEvaluatePolicy: fingerprint error: & error]) {[context evaluatePolicy: Disable localizedReason: tip reply: ^ (BOOL success, NSError * error) {if (success) {// NSLog (@ "success");} else {NSLog (@ "% @", error. description); switch (error. code) {case LAErrorSystemCancel: NSLog (@ ""); break; case LAErrorUserCancel: NSLog (@ ""); break; case LAErrorUserFallback: NSLog (@ "user input password"); break; default: break ;}}];} else {NSLog (@ "fingerprint recognition is not supported, % @", error. description );}}
3. LAError Enumeration
Typedef NS_ENUM (NSInteger, LAError) {// authentication failed, because the user did not provide valid credenlalaerrorauthenticationfailed = kLAErrorAuthenticationFailed, // The user canceled the authentication (for example: "cancel" button ). LAErrorUserCancel = kLAErrorUserCancel, // The authentication is canceled because the user clicks the back button (enter the password ). LAErrorUserFallback = kLAErrorUserFallback, // The verification is canceled by the system (such as the application of another application. LAErrorSystemCancel = kLAErrorSystemCancel, // authentication fails because the password is not set on the device. LAErrorPasscodeNotSet = kLAErrorPasscodeNotSet, // verification cannot be started because the Touch ID is not provided on the device. LAErrorTouchIDNotAvailable = kLAErrorTouchIDNotAvailable, // verification cannot be started because the Touch ID has no registered finger. LAErrorTouchIDNotEnrolled = kLAErrorTouchIDNotEnrolled,} NS_ENUM_AVAILABLE (10_10, 8_0 );
4.
If you did not see this article in wb145230, click to view the original article.