標籤: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