IOS fingerprint recognition

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.