Swift downgrades with Touch ID for fingerprint recognition

Source: Internet
Author: User

The following code is to implement the call of more than 5S device fingerprint identification code, according to the code given by the official website, will appear after a successful recognition of success after a long time to execute after the call code, stroll for a long time, just know to put it into the main thread implementation can. The specific code is as follows.

1. Introduction of class Import Localauthentication

Call the fingerprint recognition function 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'll appear on the authentication alert.            var reasonstring = "The string that prompts the user when the Fingerprint identification box is popped"//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 //put to the main thread execution, here is particularly important          If success {//call after successful you want to do things                 } else {//If authentication FA                            Iled then show a message to the console with a short description.                            In case the error is a user fallback and then show the password Alert view. println (Evalpolicyerror?).            localizeddescription)})})} else                {//If the security policy cannot is evaluated then show a short message depending on the error. Switch error!. Code {caseLAError.TouchIDNotEnrolled.rawValue:  println ("You have not saved touch                    ID fingerprint ") caseLAError.PasscodeNotSet.rawValue:println (" You have not set a password ") 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. }        }    }



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Swift downgrades with Touch ID for fingerprint recognition

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.