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