刀哥之指纹识别biometrics
指纹识别 - 生物识别
简介
- 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的更多相关文章
- iOS指纹识别
#import "ViewController.h" #import <LocalAuthentication/LocalAuthentication.h> @inte ...
- 深夜闲聊节目:华为 Mate7的指纹识别安全么?
许久没有写过不论什么东西,近期非常忙并且还要准备找工作之类的,唉... ....今天的文章也不说技术,仅仅是闲聊. 一.手机指纹识别一揽 打开非常多站点.论坛的科技栏目,充斥着各种手机讯息!仿佛手机已 ...
- Android指纹识别深入浅出分析到实战(6.0以下系统适配方案)
指纹识别这个名词听起来并不陌生,但是实际开发过程中用得并不多.Google从Android6.0(api23)开始才提供标准指纹识别支持,并对外提供指纹识别相关的接口.本文除了能适配6.0及以上系统, ...
- Android开发学习之路-指纹识别api
在android6.0之后谷歌对指纹识别进行了官方支持,今天还在放假,所以就随意尝试了一下这个api,但是遇到了各种各样的问题 ①在使用FingerPrintManager这个类实现的时候发现了很多问 ...
- 网站指纹识别工具——WhatWeb v0.4.7发布
WhatWeb是一款网站指纹识别工具,主要针对的问题是:“这个网站使用的什么技术?”WhatWeb可以告诉你网站搭建使用的程序,包括何种CMS系统.什么博客系统.Javascript库.web服务 ...
- FingerprintJS - 在浏览器端实现指纹识别
FingerprintJS 是一个快速的浏览器指纹库,纯 JavaScript 实现,没有依赖关系.默认情况下,使用 Murmur Hash 算法返回一个32位整数.Hash 函数可以很容易地更换. ...
- WAF指纹识别和XSS过滤器绕过技巧
[译文] -- “Modern Web Application Firewalls Fingerprinting and Bypassing XSS Filters” 0x1 前言 之前在乌云drop ...
- iOS 钥匙串 指纹识别 get和Post请求的区别
01-钥匙串 1. 通过系统提供的钥匙串功能可以在本地保存密码,系统使用AES的方式对密码加密 a. 查看Safari中保存的密码 2. 使用第三方框架SSKeychain把密码保存到钥匙串和获取钥匙 ...
- iOS - TouchID 指纹识别
前言 NS_CLASS_AVAILABLE(10_10, 8_0) @interface LAContext : NSObject 指纹识别功能是 iPhone 5s 推出的,SDK 是 iOS 8. ...
随机推荐
- Unity3D制作类似吃鸡的小地图
先看效果图: 实现的效果就是右上角的一个小地图,会随着人物的移动而移动,显示人物的方向,并且可以展示地图设定范围的其他的玩家 制作起来也很简单,不需要任何代码.主要原理就是先创建Render Text ...
- 图论算法(一)存图与STL第六弹——vector容器
图论算法(一)存图 我发现我的博客阅读量贼低,问小伙伴们,ta们都说这些博客太长了QAQ! 今天来个短亿点的(也短不了多少……) 进入正题,图论究竟是什么? 图论就是给你一张图,让你在这张图上进行各种 ...
- JVM对象分配
1.JVM中执行字节码new指令时: 1.1.分配内存 分配策略有两种方式:(1)指针碰撞 当JVM内存区域是连续的规整的,所有用过的内存都放在一边,空闲的内存都放在另外一边,中间放着 指针作为分界点 ...
- getting session bus failed: //bin/dbus-launch terminated abnormally with the following error: Autolaunch error: X11 initialization failed.
今天在调试dbus程序的时候,运行程序出现了getting session bus failed: //bin/dbus-launch terminated abnormally with the f ...
- Excel提取身份证出生日期②
问题场景 从user表中的身份信息中提取用户的出生日期: 以下方法也可适用于提取其他数据,不仅是身份证信息: 以下图中数据都为测试数据,不具备真实性! 场景一 user表中的18位身份证,提取出生日期 ...
- magento2 定时任务
* * * * * /usr/bin/php /www/wwwroot/m2.demo.evebit.cn/bin/magento cron:run | grep -v "Ran jobs ...
- Golang omitempty 的用法
原文链接:https://blog.csdn.net/skh2015java/article/details/90720692omitempty作用是在json数据结构转换时,当该字段的值为该字段类型 ...
- 第4篇 Scrum 冲刺博客(专✌️团队)
一.站立式会议 1.1会议图片 1.2成员完成情况 成员 昨天完成的任务 今天计划完成的任务 工作中的困难 陈忠明 按下载热度返回歌曲信息,与前端尝试交互 歌曲信息的上传/下载包 前后端交互问题 吴茂 ...
- Java 8新的时间日期库,这二十个案例看完你还学不会算我的!!!
Java对日期,日历及时间的处理一直以来都饱受诟病,尤其是它决定将java.util.Date定义为可修改的以及将SimpleDateFormat实现成非线程安全的.看来Java已经意识到需要为时间及 ...
- 区块链入门到实战(19)之以太坊(Ethereum) – 以太币
以太币的作用:防范以太坊网络被滥用和激励矿工. 与比特币网络有比特币类似,以太坊(Ethereum)也有自己的虚拟币 — 以太币. 以太币的主要作用有2个: 应用程序执行任何操作都需要支付以太币,防范 ...