iOS:指紋認識(Touch ID)の簡単な応用

12316 ワード

指紋認識(Touch ID)の簡単な応用
1、呼び出し
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    
    [self setupNotification];
    UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
    [button setTitle:@" " forState:UIControlStateNormal];
    [button addTarget:self action:@selector(actionDidClickButton:) forControlEvents:UIControlEventTouchUpInside];
    [button setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    [self.view addSubview:button];
}

- (void)actionDidClickButton:(UIButton *)sender
{
    [self touchIDTest];
}
- (void)touchIDTest
{
    [TouchIDManager validateTouchID];
}

- (void)setupNotification
{
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(actionDidReceiveValidateTouchIDSuccess) name:ValidateTouchIDSuccess object:nil];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(actionDidReceiveValidateTouchIDNotAvailable) name:ValidateTouchIDNotAvailable object:nil];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(actionDidReceiveValidateTouchIDNotEnrolled) name:ValidateTouchIDNotEnrolled object:nil];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(actionDidReceiveValidateTouchIDAuthenticationFailed) name:ValidateTouchIDAuthenticationFailed object:nil];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(actionDidReceiveValidateTouchIDCancel) name:ValidateTouchIDCancel object:nil];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(actionTouchIDLockout) name:ValidateTouchIDLockout object:nil];
}
- (void)actionDidReceiveValidateTouchIDSuccess
{
    NSLog(@"%s",__func__);
}
- (void)actionDidReceiveValidateTouchIDNotAvailable
{
    NSLog(@"%s",__func__);
}
- (void)actionDidReceiveValidateTouchIDNotEnrolled
{
    NSLog(@"%s",__func__);
}
- (void)actionDidReceiveValidateTouchIDAuthenticationFailed
{
    NSLog(@"%s",__func__);
}
- (void)actionDidReceiveValidateTouchIDCancel
{
    NSLog(@"%s",__func__);
}
- (void)actionTouchIDLockout
{
    NSLog(@"%s",__func__);
}
- (void)dealloc
{
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}

詳細:https://github.com/ITHanYong/TouchID.git