Swift UITextField .oneTimeCode Autofill does not work

Viewed 342

I'm trying to implement the one time code functionality for a sms code on iOS.

The number code e.g "8737" shows up right above the keyboard, from the Message we send e.g "Code: 8737", but when tapping the code it is not automatically inserted in the textfield.

I created a simple textfield without any customisation except

textField = UITextField()

if #available(iOS 12.0, *) {
   textField.keyboardType = .default
   textField.textContentType = .oneTimeCode
   textField.delegate = self
} else {
   // Fallback on earlier versions
}

And I implemented the delegate

func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
    return true
}

Its the only textfield on the ViewController and directly added to its view and i called becomeFirstResponder when it appears.

Question one: Is there a way to use codes mixed with numbers and letters like "AB837" ? I have tried all the phrases like "Passcode: ****" and "Code: ****" but neither is working when letters are added.

Question two: What can be done wrong, that autofill to the textfield does not work?

I tap the code which is shown above the keyboard and the delegate method is called as well, but the code is not available in any variable of the delegates method or in the clipboard.

default textfield

0 Answers
Related