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