1

我玩了一下 TouchID,我有以下问题:

TouchID 登录成功后,如何呈现一个新的 ViewController?

viewController.m 中的代码是:

#import "ViewController.h"
@import LocalAuthentication;
#import "SVProgressHUD.h"
@interface ViewController ()

@end

@implementation ViewController



- (void)viewDidLoad {
    [super viewDidLoad];

        LAContext *context = [[LAContext alloc] init];
        NSError *error;

        // check if the policy can be evaluated
        if (![context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error])
        {
            NSLog(@"error:%@", error);
            NSString *msg = [NSString stringWithFormat:@"Can't evaluate policy! %@", error.localizedDescription];
            [SVProgressHUD showErrorWithStatus:msg];
            return;
        }

        // evaluate
        [context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
                localizedReason:@"Please login through TouchID"
                          reply:
         ^(BOOL success, NSError *authenticationError) {

             dispatch_async(dispatch_get_main_queue(), ^{

                 if (success) {
                     [SVProgressHUD showSuccessWithStatus:@"Everything Worked!"];
                     //Code for new viewController should come here!
                 }
                 else {
                     NSLog(@"error:%@", authenticationError);
                     [SVProgressHUD showErrorWithStatus:[NSString stringWithFormat:@"FAILED! %@", authenticationError.localizedDescription]];
                 }
             });
         }];
    }


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

viewController.h 是标准的。它没有任何改变。感谢您的支持 :)

4

1 回答 1

1

为了呈现视图控制器,我们通常使用以下方法

  1. 如果我们正在使用情节提要,则调用以下方法

    [self performSegueWithIdentifier:@"indentifierForViewController" sender:self];

    1. 如果我们不使用情节提要,那么我们可以使用

    NextTaskViewControler *add = [[NextTaskViewControler alloc] initWithNibName:@"NextTaskViewController" bundle:nil]; [self presentViewController:nextTaskVC animated:YES completion:nil];

我建议你使用 UINavigationController,这是一个专门的视图控制器,它管理其他视图控制器,为用户提供分层导航。仅出于特定目的呈现视图控制器,例如呈现其中包含少量操作的照片。当视图层次结构变得复杂时,它很容易维护

请通过 UINavigationController 参考

于 2014-10-29T18:05:44.897 回答