iOS8使用TouchID

本文介绍了iOS8中新增的LocalAuthentication框架,该框架主要用于TouchID的授权使用。文章提供了测试代码示例,并说明了使用TouchID进行身份验证的具体流程及注意事项。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

iOS8新增了LocalAuthentication框架,用于TouchID的授权使用。亲测,目前需要用户的设备支持指纹识别并已设置锁屏,而且实际测试过程中反馈比较慢。不能直接跟第三方账号密码绑定,如果需要实现第三方应用直接指纹识别登录,需要在本地存储账号信息,指纹识别通过之后再从本地读取账号信息登录。总之,目前的指纹识别是跟设备、设备锁屏密码绑定的。测试代码:

///使用TouchID
-(void)usingTouchID
{
    LAContext *myContext = [[[LAContext alloc] init] autorelease];
    NSError *authError = nil;
    NSString *myLocalizedReasonString = @"用于指纹登录";
    if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) {
        [myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
                  localizedReason:myLocalizedReasonString
                            reply:^(BOOL success, NSError *error) {
                                if (success) {
                                    // User authenticated successfully, take appropriate action
                                    NSLog(@"成功");
                                    UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:@"Suceess" message:@"已通过指纹识别!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil] autorelease];
                                    [alertView show];
                                } else {
                                    // User did not authenticate successfully, look at error and take appropriate action
                                    NSLog(@"fail with error:%@",error);
                                    UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:@"Failed" message:[error localizedDescription] delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil] autorelease];
                                    [alertView show];
                                }
                            }];
    } else {
        // Could not evaluate policy; look at authError and present an appropriate message to user
        NSLog(@"auth with error:%@",authError);
        UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:@"Failed" message:[authError localizedDescription] delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil] autorelease];
        [alertView show];
    }
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值