gpt4 book ai didi

ios - TouchID登录成功后加载另一个View

转载 作者:行者123 更新时间:2023-11-29 12:34:59 25 4
gpt4 key购买 nike

我试了一下 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 是标准的。它没有任何变化。感谢支持:)

最佳答案

为了呈现一个 View Controller ,我们通常使用以下方法

  1. 如果我们使用 Storyboard,则调用以下方法

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

    1. 如果我们不使用 Storyboard,那么我们可以使用

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

我建议您使用 UINavigationController,这是一个专门的 View Controller ,它管理其他 View Controller 以为用户提供分层导航。仅为特定目的呈现 View Controller ,例如呈现照片,其中的操作很少。当 View 层次结构变得复杂时,它很容易维护

请通过UINavigationController Refrence

关于ios - TouchID登录成功后加载另一个View,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26637104/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com