#import "AppDelegate.h"
#import <LocalAuthentication/LocalAuthentication.h>
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillResignActive:)
name:UIApplicationWillResignActiveNotification object:nil]; //监听是否触发home键挂起程序.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidBecomeActive:)
name:UIApplicationDidBecomeActiveNotification object:nil]; //监听是否重新进入程序程序.
return YES;
}
#import "ViewController.h"
#import <LocalAuthentication/LocalAuthentication.h>
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self initTouchIDBtn];
}
//=============指纹识别==================
-(void)initTouchIDBtn{
UIButton *touchIDBtn = [UIButton buttonWithType:UIButtonTypeCustom];
touchIDBtn.frame = CGRectMake(50, 300, 60, 40);
[touchIDBtn setTitle:@"指纹" forState:UIControlStateNormal];
[touchIDBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[touchIDBtn addTarget:self action:@selector(OnTouchIDBtn:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:touchIDBtn];
}
-(void)OnTouchIDBtn:(UIButton *)sender{
if ([[UIDevice currentDevice].systemVersion floatValue] < 8.0) {
NSLog(@"不支持指纹识别");
return;
}else{
LAContext *ctx = [[LAContext alloc] init];
if ([ctx canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:nil]) {
NSLog(@"支持");
[ctx evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:@"指纹识别" reply:^(BOOL success, NSError * error) {
if (success) {
NSLog(@"识别成功");
}else{
NSLog(@"识别失败");
}
}];
}
}
}