How to enable/disable OneTimeCode feature for specific text field?

后端 未结 3 1461
故里飘歌
故里飘歌 2020-12-22 02:58

For OTP text field, I have set textContentType as oneTimeCode

if #available(iOS 12.0, *) {
     otpTextField.textContentType = .oneTimeCode
}    
相关标签:
3条回答
  • 2020-12-22 03:31

    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

    0 讨论(0)
  • 2020-12-22 03:37

    Your approach with content-type is correct , but there are few things to consider to make it work , Such as

    • Security code is only work with System keyboard. So avoid using custom keyboard.
    • Make sure otp message phrase has “code” or “passcode” and message is copyable.

    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

    0 讨论(0)
  • 2020-12-22 03:51

    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:

    • If you use a custom input view for a security code input text field, iOS cannot display the necessary AutoFill UI ((c) Apple).
    • Make sure that message that is coming in SMS contains either "code" either "passcode" and message can be copied.
    • available from iOS 12

    Reference to Official doc and this one

    0 讨论(0)
提交回复
热议问题