IOS about the implementation of TouchID fingerprint unlocking

Source: Internet
Author: User

Always want to play fingerprint unlock, the recent time more busy, the study of this fingerprint unlock. This function is still very simple to achieve, although it looks relatively tall, but for development, the more tall things are generally packaged, we only need to invoke the function can achieve quite a show.
Less nonsense, direct sticker tutorial.
Apple's fingerprint recognition offers few features, as long as you pay attention to these two features (verify that the fingerprint is supported and the fingerprint is correct).

First step: Import the necessary header files for unlocking

#import <LocalAuthentication/LocalAuthentication.h>

The second step: (This step is mainly to understand the use of the method, you can skip to see the third step of the code)

This method is to determine whether the device supports TouchID.

12 - (BOOL)canEvaluatePolicy:(LAPolicy)policy error:(NSError * __autoreleasing *)error __attribute__((swift_error(none)));

This is used to verify the TouchID, there will be a popup box out.

123 - (void)evaluatePolicy:(LAPolicy)policy       localizedReason:(NSString *)localizedReason                 reply:(void(^)(BOOLsuccess, NSError * __nullable error))reply;

Lacontext object, the property of this primary setting is Localizedfallbacktitle. This is the name of the button that is used to set the left, and the default is enter Password. is hidden when you set it to @ ". You can also set the Localizedreason property, which is used to set the prompt to indicate why you want to use touch ID.

Step Three: (Overall code)

-(void) touchesended: (Nsset<uitouch *> *) touches withevent: (uievent *)event  {     // Initializing the context object    lacontext* context = [[Lacontext alloc] init];     // This setting uses the font of the password, when [email protected] "", the button will be hidden

[Email protected] "Enter password to unlock";

//The contents of the Cancel button for this setting[email protected] "Cancel"; //Error Objectnserror* error =Nil; NSString* result =@"need to verify your touch ID"; //First Use Canevaluatepolicy to determine the device support status    if([Context canevaluatepolicy:lapolicydeviceownerauthenticationwithbiometrics error:&ERROR]) {NSLog (@"Support fingerprint Identification"); [Context Evaluatepolicy:lapolicydeviceownerauthenticationwithbiometrics Localizedreason:result reply:^ (BOOL success, Nserror *_nullable Error) {                    if(Success) {NSLog (@"Verify successful refresh of main interface"); }Else{NSLog (@"%@", error.localizeddescription); Switch(error.code) { Caselaerrorsystemcancel: {NSLog (@"system cancellation authorization, such as other app cut-in");  Break; }                             Caselaerrorusercancel: {NSLog (@"user cancels authentication touch ID");  Break; }                             Caselaerrorauthenticationfailed: {NSLog (@"Authorization Failure");  Break; }                             CaseLaerrorpasscodenotset: {NSLog (@"The system does not have a password set");  Break; }                             Caselaerrortouchidnotavailable: {NSLog (@"device Touch ID is not available, such as not open");  Break; }                             Caselaerrortouchidnotenrolled: {NSLog (@"device Touch ID not available, user not input");  Break; }                             Caselaerroruserfallback: {[[Nsoperationqueue Mainqueue] Addope Rationwithblock:^{NSLog (@"the user chooses to enter the password, switches the main thread processing");                                }];  Break; }                            default: {[[Nsoperationqueue Mainqueue] Addoperationwithblock:^{NSLog (@"other cases, switch main thread processing");                                }];  Break;    }                        }                    }                }]; }Else{NSLog (@"fingerprint recognition not supported"); Switch(error.code) { Caselaerrortouchidnotenrolled: {NSLog (@"TouchID is not enrolled");  Break; }             CaseLaerrorpasscodenotset: {NSLog (@"A passcode have not been set");  Break; }            default: {NSLog (@"TouchID Not available");  Break; }} NSLog (@"%@", error.localizeddescription); }    }

Add:

The 1.touch ID will stop the use of Touch ID when verifying three consecutive errors and need to enter the phone's password to unlock it. is still being studied.

2. During the use of the block callback in the use of Lcprogresshud, but the interface appears to die, through the view level, found that the Lcprogresshud interface is not clear, resulting in the entire interface is covered by it, forming a false impression. This is someone else's problem, mark, to prevent mistakes in the future.

Reference Link: 1.http://www.jianshu.com/p/0690a96ad5f6

2.http://blog.csdn.net/zzzzzdddddxxxxx/article/details/53513909

Accessory Demo: It contains my little demo and a packaged class Touchid.zip

IOS about the implementation of TouchID fingerprint unlocking

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.