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.