Sample code as per
awe-mt suggestion. I use function
textFieldDidChangeSelection method to find out user has used autofill. below is my sample code. Used
Timer to let
textFieldDidChangeSelection finish.
Code Block var textFieldCountWhenBeginEditing = 0 |
Code Block func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool { |
if let text = textField.text { |
textFieldCountWhenBeginEditing = text.count |
} |
return true |
} |
|
func textFieldDidChangeSelection(_ textField: UITextField) { |
if textField.text != nil && textField != self.mobileTextField { |
let text = textField.text! |
let difference = abs(text.count - textFieldCountWhenBeginEditing) |
let isTextFromSuggestion = difference > 1 && !text.isEmpty |
if isTextFromSuggestion { |
Timer.scheduledTimer(withTimeInterval: 0.2, repeats: false) { (_) in |
// Do something, its from autofill |
} |
} |
textFieldCountWhenBeginEditing = text.count |
} |
} |
|