iosswiftapple-app-site-association

One time code auto fill do not suggest code received via SMS


This is how I defined my oneTime UITextField:

let codeTextField: MaskedTextField = { // inherits from UITextField
    let textField = MaskedTextField()
    textField.textContentType = .oneTimeCode
    textField.textColor = .mineShaft
    textField.tintColor = .mineShaft
    textField.autocapitalizationType = .none
    textField.placeholderCharacter = "_"
    textField.patternMask = "___ ___"
    textField.autocorrectionType = .no
    textField.keyboardType = .numberPad
    textField.font = UIFont.poppinsMedium.withSize(17)
    textField.placeholder = "settings.code.title".localized
    return textField
}()

Why doesn't it work when SMS has been received?

This is content of SMS received:

Verification code to PLZ from 12-10-2023 14:33:20. SMS code: 678826

@partner-portal.pre-prod.plz.pl #678826

And this is screenshot from my UIView:

enter image description here


Solution

  • Solution is very simple. UITextField should not be filled at time for auto suggestion. Should be empty without any placeholders or default values.

    textField.patternMask = ""