指纹识别 - 生物识别

简介

  • iPhone 5S 开始支持
  • iOS 8.0 开放了 Touch ID 的接口

代码准备

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    [self inputUserinfo];
} /// 输入用户信息
- (void)inputUserinfo {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"购买" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"购买", nil];
alertView.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput; [alertView show];
} - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
NSLog(@"%zd", buttonIndex); if (buttonIndex == 0) {
return;
} UITextField *usernameText = [alertView textFieldAtIndex:0];
UITextField *pwdText = [alertView textFieldAtIndex:1]; if ([usernameText.text isEqualToString:@"zhang"] && [pwdText.text isEqualToString:@"123"]) {
[self purchase];
} else {
[[[UIAlertView alloc] initWithTitle:@"提示" message:@"用户名或密码错误" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil, nil] show];
}
} /// 购买
- (void)purchase {
NSLog(@"购买");
}

指纹识别

头文件

#import <LocalAuthentication/LocalAuthentication.h>

判断是否支持指纹识别

// 检查版本
if ([UIDevice currentDevice].systemVersion.floatValue < 8.0) {
[self inputUserinfo];
return;
} // 检查是否支持指纹识别
LAContext *ctx = [[LAContext alloc] init]; if ([ctx canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:NULL]) {
NSLog(@"支持指纹识别"); // 异步输入指纹
[ctx evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:@"购买" reply:^(BOOL success, NSError *error) {
NSLog(@"%d %@ %@", success, error, [NSThread currentThread]);
if (success) {
[self purchase];
} else if (error.code == LAErrorUserFallback) {
dispatch_async(dispatch_get_main_queue(), ^{
[self inputUserinfo];
});
}
}];
NSLog(@"come here");
} else {
[self inputUserinfo];
}

错误代号

错误 描述
LAErrorAuthenticationFailed 指纹无法识别
LAErrorUserCancel 用户点击了”取消”按钮
LAErrorUserFallback 用户取消,点击了”输入密码”按钮
LAErrorSystemCancel 系统取消,例如激活了其他应用程序
LAErrorPasscodeNotSet 验证无法启动,因为设备上没有设置密码
LAErrorTouchIDNotAvailable 验证无法启动,因为设备上没有 Touch ID
LAErrorTouchIDNotEnrolled 验证无法启动,因为没有输入指纹

使用 UIAlertController

- (void)inputUserInfo {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"请输入用户名和口令" preferredStyle:UIAlertControllerStyleAlert]; [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = @"请输入用户名";
}];
[alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = @"请输入用户密码";
textField.secureTextEntry = YES;
}]; [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
[self dismissViewControllerAnimated:YES completion:nil];
}]]; [alert addAction:[UIAlertAction actionWithTitle:@"购买" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
NSString *username = [alert.textFields[0] text];
NSString *pwd = [alert.textFields[1] text]; if ([username isEqualToString:@"zhang"] && [pwd isEqualToString:@"1"]) {
[self purchase];
} else {
[self showErrorMsg];
}
}]]; [self presentViewController:alert animated:YES completion:nil];
} - (void)showErrorMsg {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"用户名或密码不正确" preferredStyle:UIAlertControllerStyleAlert]; [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
[self dismissViewControllerAnimated:YES completion:nil];
}]]; [self presentViewController:alert animated:YES completion:nil];
} - (void)purchase {
NSLog(@"买了");
}

刀哥之指纹识别biometrics的更多相关文章

  1. iOS指纹识别

    #import "ViewController.h" #import <LocalAuthentication/LocalAuthentication.h> @inte ...

  2. 深夜闲聊节目:华为 Mate7的指纹识别安全么?

    许久没有写过不论什么东西,近期非常忙并且还要准备找工作之类的,唉... ....今天的文章也不说技术,仅仅是闲聊. 一.手机指纹识别一揽 打开非常多站点.论坛的科技栏目,充斥着各种手机讯息!仿佛手机已 ...

  3. Android指纹识别深入浅出分析到实战(6.0以下系统适配方案)

    指纹识别这个名词听起来并不陌生,但是实际开发过程中用得并不多.Google从Android6.0(api23)开始才提供标准指纹识别支持,并对外提供指纹识别相关的接口.本文除了能适配6.0及以上系统, ...

  4. Android开发学习之路-指纹识别api

    在android6.0之后谷歌对指纹识别进行了官方支持,今天还在放假,所以就随意尝试了一下这个api,但是遇到了各种各样的问题 ①在使用FingerPrintManager这个类实现的时候发现了很多问 ...

  5. 网站指纹识别工具——WhatWeb v0.4.7发布

      WhatWeb是一款网站指纹识别工具,主要针对的问题是:“这个网站使用的什么技术?”WhatWeb可以告诉你网站搭建使用的程序,包括何种CMS系统.什么博客系统.Javascript库.web服务 ...

  6. FingerprintJS - 在浏览器端实现指纹识别

    FingerprintJS 是一个快速的浏览器指纹库,纯 JavaScript 实现,没有依赖关系.默认情况下,使用 Murmur Hash 算法返回一个32位整数.Hash 函数可以很容易地更换. ...

  7. WAF指纹识别和XSS过滤器绕过技巧

    [译文] -- “Modern Web Application Firewalls Fingerprinting and Bypassing XSS Filters” 0x1 前言 之前在乌云drop ...

  8. iOS 钥匙串 指纹识别 get和Post请求的区别

    01-钥匙串 1. 通过系统提供的钥匙串功能可以在本地保存密码,系统使用AES的方式对密码加密 a. 查看Safari中保存的密码 2. 使用第三方框架SSKeychain把密码保存到钥匙串和获取钥匙 ...

  9. iOS - TouchID 指纹识别

    前言 NS_CLASS_AVAILABLE(10_10, 8_0) @interface LAContext : NSObject 指纹识别功能是 iPhone 5s 推出的,SDK 是 iOS 8. ...

随机推荐

  1. Solon 的 PathVariable 不需注解

    相对于 Spring boot 的 path variable :Solon 的不需注解,只要变量名对上即可: //path var demo // @XMapping("e/{p_q}/{ ...

  2. 听说同学你搞不懂Java的LinkedHashMap,可笑

    先看再点赞,给自己一点思考的时间,微信搜索[沉默王二]关注这个有颜值却假装靠才华苟且的程序员.本文 GitHub github.com/itwanger 已收录,里面还有我精心为你准备的一线大厂面试题 ...

  3. Atomic原子类

    Atomic原子类 Atomic原子类位于并发包java.util.concurrent下的java.util.concurrent.Atomic中. 1. 原子更新基本类型类 使用原子方式更新基本数 ...

  4. troubleshoot之:使用JFR分析性能问题

    目录 简介 GC性能事件 同步性能 IO性能 代码执行的性能 其他有用的event 简介 java程序的性能问题分析是一个很困难的问题.尤其是对于一个非常复杂的程序来说,分析起来更是头疼. 还好JVM ...

  5. 简单快速导出word文档

    最近,我写公司项目word导出功能,应该只有2小时的工作量,却被硬生生的拉长2天,项目上线到业务正常运行也被拉长到2个星期. 为什么如此浪费时间呢? 1)公司的项目比较老,采用硬编码模式,意味着wor ...

  6. python数据类型分类(可变(不可变)数据类型)

    一:python数据类型的分类: 可变(不可哈希)的数据类型: list 列表 dict 字典 set 集合 不可变(可哈希)的数据类型: str 字符串 bool 布尔型 int 整型 tuple ...

  7. 初识ABP vNext(4):vue用户登录&菜单权限

    Tips:本篇已加入系列文章阅读目录,可点击查看更多相关文章. 目录 前言 开始 登录 菜单权限 运行测试 最后 前言 上一篇已经创建好了前后端项目,本篇开始编码部分. 开始 几乎所有的系统都绕不开登 ...

  8. SSH 加固指南

    本文翻译自:A Guide to Securing the SSH Daemon SSH(Secure Shell)是一种能够让用户安全访问远程系统的网络协议,它为不安全网络中的两台主机提供了一个强加 ...

  9. 初学Linux (Linux_note)

    根目录:/ /root: 存放root用户相关文件 /home: 存放不同用户的相关文件 /bin: 存放常用命令的目录 /sbin: 要具有一定权限才可以使用的命令 /mnt: 默认挂载光驱和软驱的 ...

  10. 借助FRP反向代理实现内网穿透

    一.frp 是什么? frp 是一个专注于内网穿透的高性能的反向代理应用,支持 TCP.UDP.HTTP.HTTPS 等多种协议.可以将内网服务以安全.便捷的方式通过具有公网 IP 节点的中转暴露到公 ...