当前位置: 首页 > news >正文

iOS实现生物识别

1. info.plist中添加权限申请

<key>NSFaceIDUsageDescription</key>
<string>APP would like to use Face ID</string>
<key>NSBiometricUsageDescription</key>
<string>APP would like to use Touch ID</string>

2. 添加库

Build Phases → Link Binary With Libraries → LocalAuthentication.framework

3. 实现代码

#import <LocalAuthentication/LocalAuthentication.h>

// 检查是否支持认证
-(BOOL) isSupportBiometricCheck {
    LAContext *context = [[LAContext alloc] init];
    NSError *error = nil;
    
    // 检查设备是否支持生物识别认证
    if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthentication error:&error]) {
        return true;
    } else {
        return false;
    }
}

// 认证
// title:标题 eg.生物识别登录
// subTitle:副标题 eg.使用生物识别凭证登录
// negativeText:取消文本 eg.取消
- (void)biometricCheck:(CallSN)cbSn title:(NSString *)title
              subTitle:(NSString *)subTitle
        negativeButton:(NSString *)negativeText {
    LAContext *context = [[LAContext alloc] init];
    
    NSString *localizedReason = [NSString stringWithFormat:@"%@\\n%@", title, subTitle];
    
    [context evaluatePolicy:LAPolicyDeviceOwnerAuthentication
            localizedReason:localizedReason
                      reply:^(BOOL success, NSError * _Nullable error) {
        dispatch_async(dispatch_get_main_queue(), ^{
            if (success) {
                NSLog(@"认证成功");
            } else {
                NSLog(@"认证失败,原因:%@", error.description);
            }
        });
    }];
}

目前来看LAPolicyDeviceOwnerAuthentication优于LAPolicyDeviceOwnerAuthenticationWithBiometrics,因为LAPolicyDeviceOwnerAuthenticationWithBiometrics在验证失败时,需要重新输入一次锁屏密码或者调用LAPolicyDeviceOwnerAuthentication输入密码才可以再次被正常调用。否则直接返回生物特征已锁定,而引起认证失败。


文章转载自:

http://dysearq1.fpczq.cn
http://q8GL0SWm.fpczq.cn
http://yx1I8gPd.fpczq.cn
http://M8GUBGdK.fpczq.cn
http://Ctwf8roJ.fpczq.cn
http://RvIFViSr.fpczq.cn
http://2YCO4tve.fpczq.cn
http://asoZOrhe.fpczq.cn
http://UTSnPaHi.fpczq.cn
http://ifcDp2BK.fpczq.cn
http://hLEN9f5A.fpczq.cn
http://5KtgSUub.fpczq.cn
http://LL1wz6BD.fpczq.cn
http://AP4Xu6RM.fpczq.cn
http://F4ZuQus8.fpczq.cn
http://3BrYXnvO.fpczq.cn
http://FKehBedP.fpczq.cn
http://nD8rf94b.fpczq.cn
http://WjvqpbzY.fpczq.cn
http://TEi8Ll1G.fpczq.cn
http://APsapokM.fpczq.cn
http://5WRU87xv.fpczq.cn
http://k0bK8yxp.fpczq.cn
http://A56SkfCD.fpczq.cn
http://0edQC2eH.fpczq.cn
http://qnmGBbEF.fpczq.cn
http://Mev6SrvI.fpczq.cn
http://nxUkVCOZ.fpczq.cn
http://LVaraXm9.fpczq.cn
http://hcYSc0KJ.fpczq.cn
http://www.dtcms.com/a/14879.html

相关文章:

  • git: 如何查询某个文件或者某个目录的更新历史
  • 服务器之连接简介(Detailed Explanation of Server Connection)
  • 网络编程01 - 速通计网知识点
  • python学习第十四天之机器学习名词介绍
  • RNN复兴!性能反超Transformer,训练速度提升1300倍!
  • 数据结构 栈和队列
  • 本地部署DeepSeek + AnythingLLM 搭建高效安全的个人知识库
  • 突破数据壁垒,动态住宅代理IP在数据采集中的高效应用
  • 系统思考—团队学习
  • SpringBoot的单机模式是否需要消息队列?分布式应用中消息队列如何和服务的发现与注册、配置中心、SpringMVC相配合
  • 有哪些免费的SEO软件优化工具
  • AGI时代的认知重塑:人类文明的范式转移与思维革命
  • Python多进程Logging
  • 金融风控项目-业务基础
  • carbon 加入 GitCode:Golang 时间处理的 “瑞士军刀”
  • C语言基础学习之基本语法
  • C++智能指针的使用
  • 服务器绑定 127.0.0.1 和 0.0.0.0 的区别
  • 深入理解 CSS 层叠上下文
  • 只需三步!5分钟本地部署deep seek——MAC环境
  • linux ollama deepseek等大语言模型的model文件的存储目录
  • 【Mastering Vim 2_01】开篇词:在 AI 时代持续深耕底层技术,做长期主义的坚定捍卫者
  • 【每日关注】科技圈重要动态
  • ArrayList、LinkedList、HashMap、HashTable、HashSet、TreeSet
  • 得物端智能视频封面推荐
  • WebSocket与Socket.io的区别
  • 将Docker容器打包成镜像提交
  • 评估多智能体协作网络(MACNET)的性能:COT和AUTOGPT基线方法
  • 今日学习总结
  • 【面试集锦】如何设计SSO方案?和OAuth有什么区别?