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

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

内容简介:翻译自: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


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

查看所有标签

猜你喜欢:

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

复制互联网之2

复制互联网之2

文飞翔//刘伟 / 清华大学出版社 / 2011-6 / 45.00元

《复制互联网之2:2011年全球最值得模仿的100个网站》从行业的整体发展趋势中,收录了国内外最值得关注的互联网商业模式,为初创网站设计者提供了诸多可供借鉴的最具有启发价值的商业案例。此外,《复制互联网之2:2011年全球最值得模仿的100个网站》对前沿互联网产品的介绍和思考,也值得网站开发人员、产品设计人员及公司管理人员在产品和运营的创新上借鉴与参考。 作者是网易科技频道的编辑,长期致力于......一起来看看 《复制互联网之2》 这本书的介绍吧!

随机密码生成器
随机密码生成器

多种字符组合密码

URL 编码/解码
URL 编码/解码

URL 编码/解码

SHA 加密
SHA 加密

SHA 加密工具