苹果封装了指纹的代码,直接拿来用就可以了(指纹是手机已经录入的指纹)
1、导入库:
2、导入头文件:
#import "LocalAuthentication/LAContext.h" 3、调用指纹的方法: -(void)fingerprint { LAContext *myContext = [[LAContext alloc] init]; NSError *authError = nil; NSString *myLocalizedReasonString = @"请输入指纹"; if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) { [myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:myLocalizedReasonString reply:^(BOOL success, NSError *error) { if (success) { //成功之后进行的方法 UIStoryboard *sto = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; [self presentViewController:[sto instantiateViewControllerWithIdentifier:@"test"] animated:YES completion:nil]; } else { //失败之后的方法,指纹有3次识别的机会,3次都失败之后调用下面的方法 UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"提示" message:@"指纹错误" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil]; [av show]; } }]; } else { } }
4、在需要用到指纹的地方调用上面的方法就可以了,另外,指纹测试需要真机测试才可以。
另外,github上有简单的指纹应用demo,感兴趣的可以去看下,点击前往github。