[iOS/swift]调用TouchID的一个小Demo

  • 内容
  • 评论
  • 相关
if context.canEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, error: &error){
            [context.evaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, localizedReason: reasonString, reply: {
                ( success:Bool, evalPlicyError:NSError?)->Void in
 
                if success{
                    //从anthenticateuser()方法开始,在完成句柄块中和成功验证情况下
                    NSOperationQueue.mainQueue().addOperationWithBlock({ () -> Void in
                        self.loadData()
                    })
 
                }else{
//bug3:toRaw()改为rawValue
                    println(evalPlicyError?.localizedDescription)
                    switch evalPlicyError!.code{
                    case LAError.SystemCancel.rawValue:
                        println("认证被系统取消")
                    case LAError.UserCancel.rawValue:
                        println("认证被用户取消")
                    case LAError.UserFallback.rawValue:
                        println("用户选择进入自定义密码")
                        NSOperationQueue.mainQueue().addOperationWithBlock({ () -> Void in
                            self.showPasswordAlert()
                        })
                    default:
                        println("认证失败")
                        NSOperationQueue.mainQueue().addOperationWithBlock({ () -> Void in
                            self.showPasswordAlert()
                        })
                    }
                }
            })]
 
        }else{
            switch error!.code{
            case LAError.TouchIDNotEnrolled.rawValue:
                println("TouchID没被录入")
            case LAError.PasscodeNotSet.rawValue:
                println("password没有被设置")
            default:
                println("TouchID不可用")
            }
            println(error?.localizedDescription)
            self.showPasswordAlert()
        }
    }