但是,我想更改“输入密码”的功能.
创建我的身份验证时,我遵循以下教程:http://www.appcoda.com/touch-id-api-ios8/
但是,他们使用alertVIEw作为“输入密码”选项.
我想解雇touchID alertvIEw并让我的passwordTextFIEld成为第一个响应者.
当然我试过了:
self.passwordTextFIEld.becomeFirstResponder()
但这会导致错误:
2015-04-09 10:48:42.309 Formula Stocks[3933:964941] *** Assertion failure in voID _UIPerformResizeOfTextVIEwForTextContainer(NSLayoutManager *,UIVIEw<NSTextContainerVIEw> *,NSTextContainer *,NSUInteger)(),/SourceCache/UIFoundation/UIFoundation-371.13/UIFoundation/TextSystem/NSLayoutManager_Private.m:15472015-04-09 10:48:42.312 Formula Stocks[3933:964941] <nsxpcconnection: 0x1701061e0> connection to service named com.apple.CoreAuthentication.daemon: Warning: Exception caught during deCoding of received reply to message 'evaluatePolicy:options:reply:',dropPing incoming message and calling failure block.Exception: Only run on the main thread!
这是我的身份验证功能:
func requestFingerprintAuthentication() { // 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 = "Sign In." // 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 { NSOperationQueue.mainQueue().addOperationWithBlock({ () -> VoID in println("successfull signin with touchID") self.emailTextFIEld.text = emailID as! String self.passwordTextFIEld.text = passwordID as! String self.signIn(self.signInbutton) }) } 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.rawValue: println("Authentication was cancelled by the system") case LAError.UserCancel.rawValue: println("Authentication was cancelled by the user") case LAError.UserFallback.rawValue: println("User selected to enter custom password") self.passwordTextFIEld.becomeFirstResponder() default: println("Authentication Failed") self.passwordTextFIEld.becomeFirstResponder() } } })] } else{ // If the security policy cannot be evaluated then show a short message depending on the error. switch error!.code{ case LAError.touchIDNotEnrolled.rawValue: println("touchID is not enrolled") case LAError.PasscodeNotSet.rawValue: 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() self.passwordTextFIEld.becomeFirstResponder() }}
它会打印出来
Optional("Fallback authentication mechanism selected.")User selected to enter custom password
所以我知道它正在调用正确的.case
任何帮助它选择我的UITextFIEld将不胜感激!
解决方法 您需要在主线程上放置becomeFirstResponder. iOS要求所有UI *** 作都在主线程上.在使用闭包时(Objective-C中的块),您经常会在主线程上意外地关闭UI.你得到的常见错误是UI“冻结”了几秒钟.这是你需要时不在主线程上的经典案例.您的情况略有不同,但控制台中的日志给出了答案:“例外:仅在主线程上运行!”
总结以上是内存溢出为你收集整理的ios – 设置TouchID“输入密码”后备以开始编辑UITextField全部内容,希望文章能够帮你解决ios – 设置TouchID“输入密码”后备以开始编辑UITextField所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)