刀哥之指纹识别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. ...
随机推荐
- idea配置ssm框架
详细教程如下:https://blog.csdn.net/GallenZhang/article/details/5193215 https://blog.csdn.net/qq_28008917/a ...
- get customer attribute option
Mage::getResourceSingleton('customer/customer')->getAttribute('gender')->getSource()->getAl ...
- beego 快速入门
原文链接:https://beego.me/quickstart 1.安装依赖 git clone http://github.com/astaxie/beego.git git clone http ...
- 虚拟化技术之kvm WEB管理工具kimchi
在前面的博客中,我们介绍了kvm的各种工具,有基于图形管理的virt-manager.有基于命令行管理的virt-install .qemu-kvm.virsh等等:今天我们来介绍一款基于web界面的 ...
- .net core 中的经典设计模式的应用
.net core 中的经典设计模式的应用 Intro 前段时间我们介绍了23种设计模式,今天来分享一下 asp.net core 种我觉得比较典型的设计模式的应用 实例 责任链模式 asp.net ...
- 修改docker0网桥的IP段
关闭docker进程 systemctl stop docker 修改/etc/docker/daemon.json { "bip": "100.96.2.1/24&qu ...
- HTTP/3 来了,你了解它么?
作为我们网上冲浪最为常见,也经常被人忽视的 HTTP 已经更新换代到了 HTTP/3.本文简单明了的带你认识 HTTP/3 的作用. 最近二狗子看到自己存储女神婷婷照片所用的云服务商--又拍云推出了 ...
- 从零开始的SpringBoot项目 ( 五 ) 整合 Swagger 实现在线API文档的功能
综合概述 spring-boot作为当前最为流行的Java web开发脚手架,越来越多的开发者选择用其来构建企业级的RESTFul API接口.这些接口不但会服务于传统的web端(b/s),也会服务于 ...
- Java面试题(Spring Boot/Spring Cloud篇)
Spring Boot/Spring Cloud 104.什么是 spring boot? SpringBoot是一个框架,一种全新的编程规范,他的产生简化了框架的使用,所谓简化是指简化了Spring ...
- 网站seo整站优化有什么优势
http://www.wocaoseo.com/thread-314-1-1.html 现在很多企业找网络公司做网站优化,已经不再像以前那样做目标关键词,而是通过整站优化来达到企业营销目的 ...