加载成功TouchID登录
问题描述:
接连查看我打得四处TouchID了一下,我有以下问题:加载成功TouchID登录
成功TouchID登录后,我该如何提出一个新的视图控制器?
在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是非标准。没有什么改变。 感谢支持:)
答
为了呈现我们如果我们使用故事板,通常使用以下方法
-
视图控制器然后调用以下方法
[self performSegueWithIdentifier:@"indentifierForViewController" sender:self];
- 如果我们不使用故事板,那么我们可以使用
NextTaskViewControler *add = [[NextTaskViewControler alloc] initWithNibName:@"NextTaskViewController" bundle:nil]; [self presentViewController:nextTaskVC animated:YES completion:nil];
我建议你使用的UINavigationController,管理其他视图控制器为用户提供分层导航一个专门的视图控制器。呈现视图控制器只能用于特定目的,如呈现与几个动作的照片,以it.It的易维护时视图层次结构变得复杂