TouchID使用很简单,具体看业务流程要怎么走,直接上代码

1. 判断是否可用

判断机子是否直接TouchID或者是否已录入指纹

1
2
3
4
5
6
7
(BOOL)canEvaluatePolicy
{
LAContext *context = [[LAContext alloc] init];
NSError *error;
BOOL success = [context canEvaluatePolicy: LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error];
return success;
}

2. 调用认证

调用指纹认证

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
(void)evaluatePolicy
{
LAContext *context = [[LAContext alloc] init];
// show the authentication UI with our reason string
[context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:@"请验证已有指纹" reply:
^(BOOL success, NSError *authenticationError) {
dispatch_sync(dispatch_get_main_queue(), ^{
if (success) {
NSLog(@"认证成功啦");
} else {
NSLog(@"唔得啦你");
}
});
}];

}

毕竟TouchID是苹果的新功能,接上苹果的新功能,有利于做aso和申请竞品