swift - 如何仅在使用 Touch ID 授权后才执行 Segue

标签 swift authorization segue swift4 touch-id

也许有人可以提供帮助,只想使用 Segue 进行登录按钮,仅在使用 Touch ID 授权后才能传输到第二个 ViewController 但应用程序在用户按下按钮后仍执行 Segue

import UIKit
import LocalAuthentication

class LoginWindowViewController: UIViewController {


    @IBAction func loginButton(_ sender: Any) {

        let context: LAContext = LAContext()
        if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil){

            context.evaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, localizedReason: "For login you need to use your TouchID", reply: {(wasSuccessful, error) in if wasSuccessful {
                DispatchQueue.main.async {
   self.shouldPerformSegue(withIdentifier: "LoginComplete", sender: self.navigationController)
                }
            }else{
              print ("Bad TouchID")
                }


            })

        }


    }

谢谢

最佳答案

尝试实现此函数并检查它的调用位置:

override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {

}

请记住,当您从代码中调用 Segue 时,如果您已经将 Segue 操作从按钮添加到 Storyboard 中的下一个 ViewController,则应将其删除,并仅在 LoginViewController 与您的 LoginViewController 之间创建连接。想打电话

关于swift - 如何仅在使用 Touch ID 授权后才执行 Segue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47161533/

相关文章:

ios - 当用户在 TableView 中向下滚动时,如何将 UINavigationBar 背景颜色从透明更改为红色

ios - 使用 Swift 包管理器时单元测试的 "Missing required module ' XYZ '"

authorization - 根据授权限制维护 View 输出

ios - 使用 iOS 简单验证

javascript - Cypress 在使用 cy.visit() 时注销

ios - 自定义栏按钮项目不执行 segue

ios - 从 Xamarin 中的代码隐藏创建 UIViewController

swift - 带有固定行标题的 Swift 中的 UIPickerView

ios - 如何同步闭包?

不使用 Storyboard 的 iOS7 segue