For OTP text field, I have set textContentType as oneTimeCode
if #available(iOS 12.0, *) {
otpTextField.textContentType = .oneTimeCode
}
I tried all sorts of content types to prevent OTP from being suggested on the keyboard, finally this one worked
if #available(iOS 12.0, *) {
textField.textContentType = .username
}
In this case the UITextField is capturing a pin, and also has
keyboardType = .numberPad
Although that may not make a difference
Your approach with content-type is correct , but there are few things to consider to make it work , Such as
Also , I implemented this by following steps given in below link
Reference Link : https://medium.com/@shankarmadeshvaran/how-to-implement-automatic-otp-verification-in-ios-7813c6116a1d
Hope It Helps
You need to change textContentType
property in UITextField
to one of the following type:
If you have this code enabled on all textFields, this means that input type of this textFields
is one from supported list above. So make sure that you have correct textContentType
in your textFields
Note:
iOS 12
Reference to Official doc and this one