如何在iOS 8中使用Touch ID传感器

栏目: IOS · 发布时间: 6年前

内容简介:翻译自:https://stackoverflow.com/questions/24158062/how-to-use-touch-id-sensor-in-ios-8

我对iOS 8感到兴奋的最重要的事情之一是能够在iPhone 5s及更高版本上使用指纹传感器.不幸的是,我无法找到所需的框架,也不知道如何进行身份验证.请帮帮我:

>使用Touch ID需要什么框架?

>如何使用其方法以及如何验证用户?

我们非常感谢代码示例.

更完整的代码片段,快捷的风格:
func authenticateUser() {
        // 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 = "Authentication is needed to access your notes."

        // 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?) -> Void in

                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)

                    switch evalPolicyError!.code {

                    case LAError.SystemCancel.toRaw():
                        println("Authentication was cancelled by the system")

                    case LAError.UserCancel.toRaw():
                        println("Authentication was cancelled by the user")

                    case LAError.UserFallback.toRaw():
                        println("User selected to enter custom password")
                        self.showPasswordAlert()

                    default:
                        println("Authentication failed")
                        self.showPasswordAlert()
                    }
                }

            })]
        }
        else{
            // If the security policy cannot be evaluated then show a short message depending on the error.
            switch error!.code{

            case LAError.TouchIDNotEnrolled.toRaw():
                println("TouchID is not enrolled")

            case LAError.PasscodeNotSet.toRaw():
                println("A passcode has not been set")

            default:
                // The LAError.TouchIDNotAvailable case.
                println("TouchID not available")
            }

            // 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.
            self.showPasswordAlert()
        }
    }

Source

翻译自:https://stackoverflow.com/questions/24158062/how-to-use-touch-id-sensor-in-ios-8


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

SEO深度解析

SEO深度解析

痞子瑞 / 电子工业出版社 / 2014-3-1 / CNY 99.00

《SEO深度解析》以SEO从业人员普遍存在的疑问、经常讨论的问题、容易被忽视的细节以及常见的错误理论为基础,对SEO行业所包含的各方面内容进行了深入的讨论,使读者更加清晰地了解SEO及操作思路。内容分为两类:一类为作者根据自己真实、丰富的SEO经验对SEO所涉及的各种问题进行详细的讨论,主要包括SEO 基础原理剖析、SEO实操思路方法、常用工具数据剖析、竞争对手分析案例实操、网站数据分析思路指导、......一起来看看 《SEO深度解析》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具