您的位置:首页 > 移动开发 > IOS开发

IOS8 指纹解锁 Touch ID

2015-11-09 19:33 387 查看
苹果在2013年发布的新款 iPhone5s 手机支持指纹功能;

具体代码如下:

appdelegate 的界面呈现部分就不多说了;

在ViewController.m 文件中:

#import "ViewController.h"

#import <LocalAuthentication/LocalAuthentication.h>

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

if ([[self.navigationController.viewControllers firstObject] isEqual:self]) {

self.navigationItem.title = @"ViewController1";

LAContext *context = [LAContext new];

NSError *error;

context.localizedFallbackTitle = @"";// Cancel "Enter Password" option(cannot set as nil)

if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {

[context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:NSLocalizedString(@"Use Touch ID to log in.", nil) reply:^(BOOL success, NSError *error) {

if (success) {

dispatch_async(dispatch_get_main_queue(), ^{

ViewController *vc2 = [[ViewController alloc] init];

[self.navigationController pushViewController:vc2 animated:YES];

});

}

}];

} else {

NSLog(@"Touch ID is not available: %@", error);

}

} else {

self.navigationItem.title = @"ViewController2";

}

}

- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

@end

//真机测试即可
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: