IOS - 加载

时间:2017-03-24 04:53:50

标签: ios objective-c

我使用触摸ID身份验证为登录应用程序制作了一个演示。 触摸ID身份验证正常,但

我的问题是

当我使用我的触摸ID进行身份验证时,它会根据手指扫描给我立即响应,但是在发送消息之后,需要花费很多时间来进一步处理,例如前进或显示我成功的结果。 我在代码中也使用了Switch Case语句。

代码是

- (IBAction)touchidRegistration:(id)sender {
    LAContext *myContext = [[LAContext alloc] init];
    NSError *authError = nil;
    NSString *myLocalizedReasonString = @"Authenticate using your finger";
    if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) {
        self.myHud.hidden = NO;
        [myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
                  localizedReason:myLocalizedReasonString
                            reply:^(BOOL succes, NSError *error) {

                                if (succes) {

                                    self.btnRegister.enabled = YES;
                                  //  self.myHud.hidden = YES;
                                    self.registrationFlag = @"YES";
                                    self.flag = @"";
                                    self.verifiedImage.hidden = NO;
                                    NSLog(@"flag Value is %@",self.flag);
                                    NSLog(@"Done!!!");

                                    [self showMessage:@"Authentication is successful" withTitle:@"Success"];

                                    NSLog(@"User authenticated");

                                } else {

                                    switch (error.code) {
                                        case LAErrorAuthenticationFailed:
                                            self.myHud.hidden = YES;
                                            [self showMessage:@"Authentication is failed" withTitle:@"Error"];
                                            NSLog(@"Authentication Failed");
                                            break;

                                        case LAErrorUserCancel:
                                            self.myHud.hidden = YES;
                                            [self showMessage:@"You clicked on Cancel" withTitle:@"Error"];
                                            NSLog(@"User pressed Cancel button");
                                            break;

                                        case LAErrorUserFallback:
                                            self.myHud.hidden = YES;
                                            [self showMessage:@"You clicked on \"Enter Password\"" withTitle:@"Error"];
                                            NSLog(@"User pressed \"Enter Password\"");
                                            break;

                                        default:
                                            self.myHud.hidden = YES;
                                            [self showMessage:@"Touch ID is not configured" withTitle:@"Error"];
                                            NSLog(@"Touch ID is not configured");
                                            break;
                                    }

                                    NSLog(@"Authentication Fails");
                                }
                            }];
    } else {
        self.myHud.hidden = YES;
        NSLog(@"Can not evaluate Touch ID");
        [self showMessage:@"Can not evaluate TouchID" withTitle:@"Error"];

    }
}

请帮助我们或建议我任何链接我无法在这里搜索此类问题。我已经看过一个但是对于Swift,我需要目标 - C 链接: - swift - touchID takes long time to load

注意: - 我正在使用I-Phone 6设备进行测试。 提前谢谢。

1 个答案:

答案 0 :(得分:1)

最后我得到了答案, 它的工作正常对我来说谢谢

if (succes) {

                                    NSOperationQueue *myQueue = [[NSOperationQueue alloc] init];
                                    [myQueue addOperationWithBlock:^{

                                        // Background work

                                        [[NSOperationQueue mainQueue] addOperationWithBlock:^{
                                            // Main thread work (UI usually)
                                            NSMutableDictionary *userInfo = [StaticClass getTouchIdData:@"userInfo"];
                                            if(!([userInfo count] == 0))
                                            {
                                                self.myHud.hidden = YES;
                                                self.flag = @"";
                                                TestViewController *testView = [[TestViewController alloc]initWithNibName:@"TestViewController" bundle:nil];
                                                [testView setUserInfo:userInfo];
                                                [self.navigationController pushViewController:testView animated:YES];
                                            }
                                            else
                                            {
                                                self.myHud.hidden = YES;
                                                self.flag = @"YES";
                                                self.registrationFlag = @"";
                                                [self showMessage:@"For The First time user ,You have to login manually" withTitle:@"Error"];
                                                self.touchIdLoginView.hidden = YES;
                                            }
                                            NSLog(@"User Id is %@",userInfo);
                                            NSLog(@"Done!!!");
                                            NSLog(@"User authenticated");

                                        }];
                                    }];