如下代码是实现调用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 = "d出指纹识别框时提示用户的字符串" // 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. } } }
总结
以上是内存溢出为你收集整理的Swift下调用Touch ID实现指纹识别全部内容,希望文章能够帮你解决Swift下调用Touch ID实现指纹识别所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)