1.首先要引入一个头文件
#import <LocalAuthentication/LocalAuthentication.h>
2.具体代码
// 1.判断是否支持
if ([UIDevice currentDevice].systemVersion.floatValue < 8.0) {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:@"您的手机不支持指纹识别,请用其他方式登录。" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {}];
[alertController addAction:cancel];
[self presentViewController:alertController animated:YES completion:nil];
return;
}
// 2.初始化上下文对象
LAContext *context = [[LAContext alloc]init];
// 默认的提示框有两个按钮 一个取消,一个密码登录,这里可以把密码登录
// 这里把密码登录至为空了
context.localizedFallbackTitle = @"";
//错误对象
NSError *error;
// 3.首先使用判断设备支持状态
if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {
//支持指纹验证
// 这里可以修改提示框的默认文字
[context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:NSLocalizedString(@"请验证指纹", nil) reply:
^(BOOL success, NSError *authenticationError) {
if (success) {
// 4.成功回调
/*
具体操作、、、
*/
} else {
// 5.失败回调
/*
具体操作、、、
*/
}
}];
} else {
// 6.不支持指纹识别
NSLog(@"\n%@",error);
}
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。