Today's project uses fingerprint recognition, but the single fingerprint recognition technology is not complex to implement, but it needs to refresh the UI after the validation is successful here I jumped into a hole??????. because fingerprint verification is also done on a child thread
Either to wait for a long time, or to report a mess of mistakes, I was drunk to see
#import "ViewController.h"
Local authentication framework for fingerprint identification (IOS8 appears)
#import <LocalAuthentication/LocalAuthentication.h>
@interface Viewcontroller ()
@end
@implementation Viewcontroller
-(void) Viewdidload {
[Super Viewdidload];
Additional setup after loading the view, typically from a nib.
}
-(void) Touchesbegan: (Nsset<uitouch *> *) touches withevent: (uievent *) event{
Determine if fingerprint unlock is available, no API, use can to determine (consistent with camera input)
1. Create an authentication context
Lacontext *context = [[Lacontext alloc] init];
2. Judging the device to recognize
/**
Policy device (device) owner (owner): Device owner
Authentication: Certification
Biometics: Timely biometric identification (fingerprint unlocking, face recognition, iris recognition)
*/
Lapolicydeviceownerauthenticationwithbiometrics
Lapolicydeviceownerauthentication//ios9 Type (the difference from iOS8 is that after multiple click errors, click Enter password will pop up the password page, iOS8 not)
if ([Context canevaluatepolicy:lapolicydeviceownerauthentication Error:nil]) {
To start validating Lapolicydeviceownerauthentication This enumeration value, you need to verify with the above that the device can be written consistently.
[Context evaluatepolicy:lapolicydeviceownerauthentication localizedreason:@ "pop-up fingerprint Verification description" reply:^ (BOOL success, Nserror * _nullable error) {
if (success) {
Code return 0 for certification success
NSLog (@ "Certified success-->%zd", Error.code);
} else {
In actual development, users need to do different business logic processing for code type.
/**
-2: User Active Click Cancel
-1: Three-time identification error
-8: Three recognition errors continue to identify errors two times (this time the password box will pop up)
0: Successful Certification
*/
NSLog (@ "%zd", Error.code);
///Special Note: Fingerprint recognition is also in a child thread, and refreshing the UI needs to go back to the child thread
Otherwise, you can wait a long time, or you will report some strange mistakes, I am fell here??
Dispatch_after (Dispatch_time (Dispatch_time_now, (int64_t) (0.1 * nsec_per_sec)), Dispatch_get_main_queue (), ^{
Self.view.backgroundColor = [Uicolor Greencolor];
});
}
}];
} else {
NSLog (@ "Device not supported");
}
}
IOS fingerprint recognition