IOS TouchID Fingerprint identification

Source: Internet
Author: User

//
Viewcontroller.m
TouchID
//
Created by Cheze on 16/4/1.
COPYRIGHT©2016 year Xiezefeng. All rights reserved.
//

#import "ViewController.h"
#import <LocalAuthentication/LocalAuthentication.h>
@interface Viewcontroller ()
Verify that the device supports touch ID
-(BOOL) Canevaluatepolicy: (lapolicy) Policy error: (NSERROR * __autoreleasing *) error;
Callbacks for validation
-(void) EvaluatePolicy: (lapolicy) Policy
Localizedreason: (NSString *) Localizedreason
Reply: (void (^) (BOOL success, Nserror *error)) reply;
The title of the button to cancel Touch ID verification, the default title is to enter a password
@property (nonatomic, copy) NSString *localizedfallbacktitle;
@end

@implementation Viewcontroller

-(void) Viewdidload {
[Super Viewdidload];
New Lacontext Instance
Lacontext *authenticationcontext= [[Lacontext alloc]init];
Nserror *error;
1: Check if touch ID is available
if ([Authenticationcontext canevaluatepolicy:lapolicydeviceownerauthenticationwithbiometrics Error:&error]) {
NSLog (@ "touchId available");
2: Execute Authentication Policy
[Authenticationcontext Evaluatepolicy:lapolicydeviceownerauthenticationwithbiometrics localizedReason:@] Need to verify your fingerprint to confirm your identity "reply:^ (BOOL success, Nserror * _nullable error) {
if (success) {
NSLog (@ "Through Touch ID fingerprint verification");
}else{
NSLog (@ "error===%@", error);
NSLog (@ "Code====%ld", Error.code);
NSLog (@ "Errorstr ======%@", [Error.userinfo Objectforkey:nslocalizeddescriptionkey]);
if (Error.code = =-2) {//Click the Cancel button
NSLog (@ "Click the Cancel button");
}else if (Error.code = =-3) {//Dot input password button
NSLog (@ "Dot input password button");
}else if (Error.code = =-1) {//three consecutive fingerprint recognition errors
NSLog (@ "Three consecutive fingerprint recognition errors");
}else if (Error.code = =-4) {//Press the Power key
NSLog (@ "Press the Power Key");
}else if (Error.code = = -8) {//touch id function is locked, the next time you need to enter the system password
NSLog (@ "Touch ID function is locked, the next time you need to enter the system password");
}
NSLog (@ "did not pass Touch ID fingerprint verification");
}
}];
}else{
Todo Goto Enter Password page
NSLog (@ "error====%@", error);
NSLog (@ "Sorry, touchId not available");
}

Lacontext *lacontext = [[Lacontext alloc] init];
Nserror *error;
//
if ([Lacontext canevaluatepolicy:lapolicydeviceownerauthenticationwithbiometrics Error:&error]) {
//
[Lacontext Evaluatepolicy:lapolicydeviceownerauthenticationwithbiometrics
localizedreason:@, "Do you allow the fingerprint identification of front brother?"
reply:^ (BOOL success, Nserror *error) {
if (success) {
NSLog (@ "success to evaluate");
Do your
//                                }
if (Error) {
NSLog (@ "---failed to evaluate---error:%@---", error.description);
Do your error handle
//                                }
//                            }];
//    }
else {
NSLog (@ "==========not support:%@", error.description);
Do your error handle
//    }
Additional setup after loading the view, typically from a nib.
}

-(void) didreceivememorywarning {
[Super didreceivememorywarning];
Dispose of any resources the can be recreated.
}

@end

IOS TouchID Fingerprint identification

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.