首页 > 解决方案 > iOS Local Biometric authentication dialogue called again and again

问题描述

Below is my code. When ever I run this code and validate the app using TouchID, TouchID Authentication dialog is dismissed and viewDidLoad() is called again which in turn shows the TouchID alert again. So I am not able to leave this page and stuck in a loop. Any help would be appreciated. Note: Same code was working fine 2 days ago.

    override func viewDidLoad() {
        super.viewDidLoad()
        initialSetup()
        checkAuthenticationMethod()

    }

    private func checkAuthenticationMethod() {
        let biometricsEnabled = UserDefaults.standard.bool(forKey: LocalDefaults.biometricsEnabled.rawValue)
        if biometricsEnabled {
            OperationQueue.main.addOperation {
                self.setupLocalAuthentication()
            }
        }
    }


    private func setupLocalAuthentication() {

    var error: NSError?
    context.localizedCancelTitle = "Login using your PIN"
    if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) {
        if let err = error {
            self.showAlert(message: err.localizedDescription, withTitle: "Error", willViewPop: false)
        }else {
            self.localAuthenticationMessage.isHidden = false
            context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: "Unlock App") { (success, error) in
                DispatchQueue.main.async { [weak self] in
                    self?.view.isUserInteractionEnabled = !success
                    if success {
                        self?.showHUDLoader(containerView: nil,message: "Logging in", enableInteraction: false)
                        self?.pinImage.image = UIImage(named: "PIN_4")
                        self?.updateUserLoginToken()
                    }else if let err = error {
                        self?.pinImage.image = UIImage(named: "PIN_0")
                        let errorCode = (err as NSError).code
                        if errorCode != -4 {
                            self?.localAuthenticationMessage.isHidden = true

                        }
                    }
                }
            }
        }
    }
}

标签: iosswiftauthenticationtouch-idface-id

解决方案


推荐阅读