iOS8新增了LocalAuthentication框架,用于TouchID的受权使用。亲測,眼下需要用户的设备支持指纹识别并已设置锁屏,而且实际測试过程当中反馈比較慢。不能直接跟第三方帐号password绑定,假设需要实现第三方应用直接指纹识别登陆,需要在本地存储帐号信息,指纹识别经过以后再从本地读取帐号信息登陆。总之。眼下的指纹识别是跟设备、设备锁屏password绑定的。app
測试代码:框架
///使用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]; } }