iOS关于手势密码和指纹密码那些事

在系统设置里面会有一个TounchID和手势密码的开关UISwitch,需要手动开启设置自己的密码,注意需要先判断设备是否支持指纹识别,苹果5S以上开始识别,安卓机比较多,在安卓6.0系统开始支持指纹的登录功能

iOS 设备上支持TouchID语句,

LAPolicyDeviceOwnerAuthentication---枚举类型--支持指纹登陆

LAPolicyDeviceOwnerAuthenticationWithBiometrics   ---枚举类型  支持指纹登录和密码登录  指纹识别失败输入设备密码进入

 BOOL isSupported = [context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:NULL];

    [[NSUserDefaults standardUserDefaults] setBool:isSupported forKey:@"supported"];

根据组合的逻辑,手势密码有开 关 两种状态  指纹设备有两种状态,这样就有2x2=4种状态

//手势密码比较简单,不再赘述,这里重点说一下指纹登录

- (void)showTouchIdView

{

   [self.context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics

                localizedReason:@"通过验证指纹解锁"

                         reply:^(BOOL success, NSError * _Nullable error) {

                              if (success)

                              {

                                 [self hide];

                               }

                          }];

    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {

        // 支持指纹识别

        if ([self.context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:nil]) {

            // 指纹识别可用

            [self.context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics

                    localizedReason:@"请使用指纹登陆"

                              reply:^(BOOL success, NSError* error) {

                                  if (success) {

                                      

                                      NSLog(@"识别成功");

                                      [[NSOperationQueue mainQueue] addOperationWithBlock:^{

//识别成功在线程进行的操作

                               }

                                  else {

                                      if (error.code == kLAErrorUserFallback) {

                                          NSLog(@"用户点击了输入密码");

                                          [[NSOperationQueue mainQueue] addOperationWithBlock:^{

                                           

                                          }];

                                          

                                      }

                                      else if (error.code == kLAErrorUserCancel) {

                                          //NSLog(@"用户点击了取消");

                                                                           }

                                      else {

                                          [[NSOperationQueue mainQueue] addOperationWithBlock:^{

//                                              识别失败

                                          }];

                                          

                                          

                                          NSLog(@"识别失败");

                                      }

                                  }

                                  

                              }];

        }

    }

}

//可以在APPDelegate实例中声明其中的逻辑操作

#pragma mark --根据4种情况进行逻辑判断分析

- (void)showViewController{

    //对手势密码进行排列组合

    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"gesture"]==YES&&[[NSUserDefaults standardUserDefaults] boolForKey:@"touchID"]==YES) {

        //开启了手势密码和指纹密码

        //先验证指纹密码再验证手势密码

        PersonViewController *person= [[PersonViewController alloc] init];

        person.gestureAndLock = @"1";

        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:person];

        self.window.rootViewController = nav;

 

    }else if ([[NSUserDefaults standardUserDefaults] boolForKey:@"gesture"]==YES&&[[NSUserDefaults standardUserDefaults] boolForKey:@"touchID"]==NO){

        //开启了手势密码和关闭touchID

        WUGesturesUnlockViewController *vc = [[WUGesturesUnlockViewController alloc] initWithUnlockType:WUUnlockTypeValidatePwd];

        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];

        vc.isLogin = YES;

        self.window.rootViewController = nav;

    }else if ([[NSUserDefaults standardUserDefaults] boolForKey:@"gesture"]==NO&&[[NSUserDefaults standardUserDefaults] boolForKey:@"touchID"]==YES){

        //开启了指纹登陆和关闭了手势密码登录

        PersonViewController *person= [[PersonViewController alloc] init];

        person.gestureAndLock = @"0";

        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:person];

        self.window.rootViewController = nav;

    }

    else{

        //初次进入和手势密码和TouchID默认都是关闭

        LoginViewController *loginCtrl = [[LoginViewController alloc] init];

        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:loginCtrl];

        self.window.rootViewController =nav;

    }

}

 //这样就可以进入相应的控制器

 

posted @ 2016-12-27 17:57  tryFighting  阅读(469)  评论(0编辑  收藏  举报