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 phone fingerprint with home key"; //determine if the phone has fingerprints if([Context Canevaluatepolicy:lapolicydeviceownerauthenticationwithbiometrics error:&ERROR]) {[Context evaluatepolicy:lapolicydeviceownerauthenticationwithbiometrics Localizedreason:tip reply:^ (BOOL success, Nserror *error) { if(Success) {//Validation SuccessfulNSLog (@"Success"); } Else{NSLog (@"%@", error.description); Switch(error.code) { CaseLaerrorsystemcancel:nslog (@"System Cancellation Authorization"); Break; CaseLaerrorusercancel:nslog (@"User canceled"); Break; CaseLaerroruserfallback:nslog (@"user Input Password"); Break; default: Break; } } }]; } Else{NSLog (@"fingerprint recognition not supported,%@", error.description); }}
3.Laerror Enumeration related explanations
typedef ns_enum (Nsinteger, laerror) {///authentication was unsuccessful because the user did not provide valid credentialslaerrorauthenticationfailed =klaerrorauthenticationfailed,///canceled by the user (for example: "Cancel" button). Laerrorusercancel =Klaerrorusercancel,///the authentication was canceled because the user clicked the Fallback button (enter the password). Laerroruserfallback =Klaerroruserfallback,///validation is canceled through the system (for example, another application's application). Laerrorsystemcancel =Klaerrorsystemcancel,///authentication failed to start because the password was not set on the device. Laerrorpasscodenotset =Klaerrorpasscodenotset,///validation cannot be initiated because the Touch ID is not provided on the device. Laerrortouchidnotavailable =klaerrortouchidnotavailable,///validation cannot be started because the touch identity does not have a finger registered. laerrortouchidnotenrolled =klaerrortouchidnotenrolled,} Ns_enum_available (10_10, 8_0);
4.
If you do not see this article in the wb145230 Blog Park, please click here to view the original.
IOS Touch ID uses