Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 12 Suggested strong password textfield delegate callback for Choose My Own Password

In iOS 12 I have a new password textfield for a sign up flow and I want the system to suggest a strong one. I also have a button that enables and disables based on the delegate method and I do some changes etc.

textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String)

This works good for enabling it when the user taps Use Strong Password. But I don't seem to get a delegate callback for when a user might tap Choose My Own Password and a s a result my button enable/disable logic never gets a chance to execute, allowing someone to sign up with a blank password.

Suggested password

Any ideas on what I might have t do to get a callback when the user taps Choose my own password? Any help is greatly appreciated.

like image 504
Andrew Edwards Avatar asked Dec 01 '18 00:12

Andrew Edwards


1 Answers

I faced the same issue, but the only thing I found out was providing callbacks was the viewDidLayoutSubviews delegate of the UIView

So what I did is use this:

override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        if passwordTextField.isFirstResponder {
           validatePassword(passwordTextField.text ?? "")
        }
    }
like image 114
Lefteris Avatar answered Oct 01 '22 05:10

Lefteris