码迷,mamicode.com
首页 > 移动开发 > 详细

iOS8使用TouchID

时间:2014-10-21 17:54:53      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   color   io   os   ar   使用   sp   

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];
    }
}



iOS8使用TouchID

标签:des   style   blog   color   io   os   ar   使用   sp   

原文地址:http://blog.csdn.net/nextstudio/article/details/40345869

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!