zoukankan      html  css  js  c++  java
  • Swift下调用Touch ID实现指纹识别

    iOS开发交流群:484884085

    欢迎大家增加。


    例如以下代码是实现调用5S以上设备指纹识别的代码,依照官网给出的代码,会出现识别成功后非常久才运行成功后调用的代码,逛了非常久的。才知道要将其放入主线程实现才干够。

    详细代码例如以下。

    1、引入类  import LocalAuthentication

    //调用指纹识别函数
        func loginWithTouchID()
        {
            if((UIDevice.currentDevice().systemVersionasNSString).floatValue >= 8.0)
            {
                // Get the local authentication context.
                let context = LAContext()
                // Declare a NSError variable.
                var error: NSError?

    // Set the reason string that will appear on the authentication alert. var reasonString = "弹出指纹识别框时提示用户的字符串" // Check if the device can evaluate the policy. if context.canEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, error: &error) { context.evaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, localizedReason: reasonString, reply: { (success: Bool, evalPolicyError: NSError?) -> Voidin dispatch_async(dispatch_get_main_queue(), { () -> Voidin //放到主线程运行。这里特别重要 if success { //调用成功后你想做的事情 } else { // If authentication failed then show a message to the console with a short description. // In case that the error is a user fallback, then show the password alert view. println(evalPolicyError?.localizedDescription) } }) }) } else { // If the security policy cannot be evaluated then show a short message depending on the error. switch error!.code { caseLAError.TouchIDNotEnrolled.rawValue:  println("您还没有保存TouchID指纹") caseLAError.PasscodeNotSet.rawValue: println("您还没有设置密码") default: // The LAError.TouchIDNotAvailable case. println("TouchID不可用") } // Optionally the error description can be displayed on the console. println(error?.localizedDescription) // Show the custom alert view to allow users to enter the password. } } }


    
  • 相关阅读:
    【转】C#控件——DataGridView单元格文本自动换行
    【转】右键的 在 vs 中打开 怎么去掉
    【转】C#使用Oracle.ManagedDataAccess.dll
    C#委托笔记
    【转】检索 COM 类工厂中 CLSID 为 {00024500-0000-0000-C000-000000000046} 的组件失败,原因是出现以下错误: 80070005 拒绝访问
    js创建ActiveXObject无效
    ASPxGridView编辑时弹出的editform值不是当前行值的原因
    ASPxGridView后台实现隐藏新增按钮
    oracle闪回存储过程
    oracle重新编译所有invalid objects
  • 原文地址:https://www.cnblogs.com/mfmdaoyou/p/7219008.html
Copyright © 2011-2022 走看看