//
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