TouchID的使用

来源:互联网 发布:ae软件下载 编辑:程序博客网 时间:2024/06/06 10:45
////  ViewController.m//  touchID_Demo_oc////  Created by Blake on 14/12/8.//  Copyright (c) 2014年 Blake. All rights reserved.//#import "ViewController.h"#import <LocalAuthentication/LocalAuthentication.h>@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad {    [super viewDidLoad];    // Do any additional setup after loading the view, typically from a nib.}- (IBAction)clicked:(UIButton *)sender {        LAContext* lacontext = [LAContext new];    NSError* error = nil;        if ([lacontext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {        [lacontext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:@"APP需要验证您的指纹信息" reply:^(BOOL success, NSError *error) {                        if (success) {                UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"验证成功" preferredStyle:UIAlertControllerStyleAlert];                [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:nil]];                                [self presentViewController:alert animated:YES completion:nil];                            }else{                UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"验证失败" preferredStyle:UIAlertControllerStyleAlert];                [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:nil]];                  [self presentViewController:alert animated:YES completion:nil];            }                    }];            }else{            UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"设备无法验证,请输入密码" preferredStyle:UIAlertControllerStyleAlert];        [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:nil]];          [self presentViewController:alert animated:YES completion:nil];        }}- (void)didReceiveMemoryWarning {    [super didReceiveMemoryWarning];    // Dispose of any resources that can be recreated.}@end

随着新款iPhone,iPad等电子设备上市,越来越多的设备开始支持touchID,touchID的用法很简单,做一个简单地例子贴出来,
0 0
原创粉丝点击