IOS8 指纹解锁 Touch ID
2015-11-09 19:33
387 查看
苹果在2013年发布的新款 iPhone5s 手机支持指纹功能;
具体代码如下:
appdelegate 的界面呈现部分就不多说了;
在ViewController.m 文件中:
#import "ViewController.h"
#import <LocalAuthentication/LocalAuthentication.h>
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
if ([[self.navigationController.viewControllers firstObject] isEqual:self]) {
self.navigationItem.title = @"ViewController1";
LAContext *context = [LAContext new];
NSError *error;
context.localizedFallbackTitle = @"";// Cancel "Enter Password" option(cannot set as nil)
if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {
[context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:NSLocalizedString(@"Use Touch ID to log in.", nil) reply:^(BOOL success, NSError *error) {
if (success) {
dispatch_async(dispatch_get_main_queue(), ^{
ViewController *vc2 = [[ViewController alloc] init];
[self.navigationController pushViewController:vc2 animated:YES];
});
}
}];
} else {
NSLog(@"Touch ID is not available: %@", error);
}
} else {
self.navigationItem.title = @"ViewController2";
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
//真机测试即可
具体代码如下:
appdelegate 的界面呈现部分就不多说了;
在ViewController.m 文件中:
#import "ViewController.h"
#import <LocalAuthentication/LocalAuthentication.h>
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
if ([[self.navigationController.viewControllers firstObject] isEqual:self]) {
self.navigationItem.title = @"ViewController1";
LAContext *context = [LAContext new];
NSError *error;
context.localizedFallbackTitle = @"";// Cancel "Enter Password" option(cannot set as nil)
if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {
[context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:NSLocalizedString(@"Use Touch ID to log in.", nil) reply:^(BOOL success, NSError *error) {
if (success) {
dispatch_async(dispatch_get_main_queue(), ^{
ViewController *vc2 = [[ViewController alloc] init];
[self.navigationController pushViewController:vc2 animated:YES];
});
}
}];
} else {
NSLog(@"Touch ID is not available: %@", error);
}
} else {
self.navigationItem.title = @"ViewController2";
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
//真机测试即可
相关文章推荐
- 海康SDK修改分辨率
- [iOS基础]文件读取详解
- Xcode 工程设置及含义
- iOS中的ARC---ARC规则
- IOS 百叶窗动画
- iOS-获取当前时间的年、月、日、时、分、秒
- 在 ios 与 android 同时支持js功能,即web与app的交互功能的实现
- iOS 更改textField里placeholder的字体和颜色
- ios 下拉列表
- 利用Core Plot绘制折线图
- iOS 9以上系统调用不了支付宝客户端只能调用网页解决方法
- nagios_自定义宏变量隐藏发送邮件账号的敏感信息
- iOS 中捕获程序崩溃日志
- 关于iOS9中的App Transport Security相关说明及适配
- 仿ios选择器以及相应的多选栏目
- nagios Event Handlers
- ios 常用字符串的操作
- iOS中使用Masonry的简介
- ios崩溃日志分析
- ios 3D Touch