#import "AppDelegate.h"
#import "ViewController.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//appdelegate
_window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
_window.backgroundColor = [UIColor whiteColor];
[_window makeKeyAndVisible];
ViewController *vc = [[ViewController alloc]init];
UINavigationController *na = [[UINavigationController alloc]initWithRootViewController:vc];
_window.rootViewController = na;
return YES;
}
-canEvaluatePolicy:error: //-(BOOL)canEvaluatePolicy:(LAPolicy)policy error:(NSError * __autoreleasing *)error __attribute__((swift_error(none))); -evaluatePolicy:localizedReason:reply: //- (void)evaluatePolicy:(LAPolicy)policy localizedReason:(NSString *)localizedReason reply:(void(^)(BOOL success, NSError * __nullable error))reply;
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"TouchIDSimpleDemoOne";
LAContext *context = [[LAContext alloc]init];
NSError *error;
NSString *result = @"需要你身份验证呢";
if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error])
{
[context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:result reply:^(BOOL success, NSError *error)
{
if (success)
{
//验证成功,主线程处理UI
//这个地方呢就是写一些验证成功之后需要做些什么事情的代码。
NSLog(@"验证成功");
}
else
{
//以下是一些验证失败的原因啥的
NSLog(@"%@",error.localizedDescription);
switch (error.code) {
case LAErrorSystemCancel:
{
NSLog(@"切换到其他APP,系统取消验证Touch ID");
//切换到其他APP,系统取消验证Touch ID
break;
}
case LAErrorUserCancel:
{
NSLog(@"用户取消验证Touch ID");
//用户取消验证Touch ID
break;
}
case LAErrorUserFallback:
{
NSLog(@"用户选择输入密码");
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
//用户选择其他验证方式,切换主线程处理
}];
break;
}
default:
{
NSLog(@"LAErrorAuthenticationFailed,授权失败");
//授权失败
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
//其他情况,切换主线程处理
}];
break;
}
}
}
}];
}else
{
//不支持指纹识别,LOG出错误详情
switch (error.code) {
case LAErrorTouchIDNotEnrolled:
{
NSLog(@"设备Touch ID不可用,用户未录入");
break;
}
case LAErrorPasscodeNotSet:
{
NSLog(@"系统未设置密码");
break;
}
case LAErrorTouchIDNotAvailable:
{
NSLog(@"设备Touch ID不可用,例如未打开");
break;
}
default:
{
NSLog(@"系统未设置密码");
break;
}
}
NSLog(@"%@",error.localizedDescription);
}
}
//指纹验证返回值
typedef NS_ENUM(NSInteger, LAError)
{
/// Authentication was not successful, because user failed to provide valid credentials.
LAErrorAuthenticationFailed = kLAErrorAuthenticationFailed,
/// Authentication was canceled by user (e.g. tapped Cancel button).
LAErrorUserCancel = kLAErrorUserCancel,
/// Authentication was canceled, because the user tapped the fallback button (Enter Password).
LAErrorUserFallback = kLAErrorUserFallback,
/// Authentication was canceled by system (e.g. another application went to foreground).
LAErrorSystemCancel = kLAErrorSystemCancel,
/// Authentication could not start, because passcode is not set on the device.
LAErrorPasscodeNotSet = kLAErrorPasscodeNotSet,
/// Authentication could not start, because Touch ID is not available on the device.
LAErrorTouchIDNotAvailable = kLAErrorTouchIDNotAvailable,
/// Authentication could not start, because Touch ID has no enrolled fingers.
LAErrorTouchIDNotEnrolled = kLAErrorTouchIDNotEnrolled,
/// Authentication was not successful, because there were too many failed Touch ID attempts and
/// Touch ID is now locked. Passcode is required to unlock Touch ID, e.g. evaluating
/// LAPolicyDeviceOwnerAuthenticationWithBiometrics will ask for passcode as a prerequisite.
LAErrorTouchIDLockout NS_ENUM_AVAILABLE(10_11, 9_0) = kLAErrorTouchIDLockout,
/// Authentication was canceled by application (e.g. invalidate was called while
/// authentication was in progress).
LAErrorAppCancel NS_ENUM_AVAILABLE(10_11, 9_0) = kLAErrorAppCancel,
/// LAContext passed to this call has been previously invalidated.
LAErrorInvalidContext NS_ENUM_AVAILABLE(10_11, 9_0) = kLAErrorInvalidContext
} NS_ENUM_AVAILABLE(10_10, 8_0);
- (void)viewDidLoad {
[super viewDidLoad];
//初始化
WJTouchID *touchid = [[WJTouchID alloc]init];
[touchid startWJTouchIDWithMessage:WJNotice(@"自定义信息", @"The Custom Message") fallbackTitle:WJNotice(@"", @"Fallback Title") delegate:self];
self.touchID = touchid;
}
@required //TouchID验证成功 - (void)WJTouchIDAuthorizeSuccess; //TouchID验证失败 - (void)WJTouchIDAuthorizeFailure; @optional //当前设备不支持指纹识别 - (void)WJTouchIDIsNotSupport; //当前软件被挂起取消了授权(如突然来了电话,应用进入前台) - (void)WJTouchIDAuthorizeErrorAppCancel; //取消TouchID验证 (用户点击了取消) - (void)WJTouchIDAuthorizeErrorUserCancel; //在TouchID对话框中点击输入密码按钮 - (void)WJTouchIDAuthorizeErrorUserFallback; //在验证的TouchID的过程中被系统取消 例如突然来电话、按了Home键、锁屏... - (void)WJTouchIDAuthorizeErrorSystemCancel; //无法启用TouchID,设备没有设置密码 - (void)WJTouchIDAuthorizeErrorPasscodeNotSet; //多次连续使用Touch ID失败,Touch ID被锁,需要用户输入密码解锁 - (void)WJTouchIDAuthorizeErrorTouchIDLockout; //当前软件被挂起取消了授权 (授权过程中,LAContext对象被释) - (void)WJTouchIDAuthorizeErrorInvalidContext; //设备没有录入TouchID,无法启用TouchID - (void)WJTouchIDAuthorizeErrorTouchIDNotEnrolled; //该设备的TouchID无效 - (void)WJTouchIDAuthorizeErrorTouchIDNotAvailable;
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有