How to detect when user used Password AutoFill on a UITextField

前端 未结 7 2163
半阙折子戏
半阙折子戏 2020-12-10 03:26

I\'ve implemented all the app and server changes necessary to support Password Autofill on iOS 11, and it works well. I\'d like it to work a little better.

My usern

7条回答
  •  温柔的废话
    2020-12-10 04:07

    Swift 5:

    The following delegate method gets triggered every time that the user types something in the textfield. That string count is usually one, so any number great than that is either autofill or the user pasting some text into the field. I am only using this delegate on this password field.

    extension LoginView: UITextFieldDelegate {
    
        func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
            if string.count > 1 {
                DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(1)) { [weak self] in
                    self?.endEditing(true)
                }
            }
            return true
        }
    }
    

提交回复
热议问题