iOS 11 disable password autofill accessory view option?

后端 未结 20 2568
孤独总比滥情好
孤独总比滥情好 2020-11-28 04:20

As of now I would like to opt out of the new option iOS 11 gives, that is to suggest passwords in the app. When I run the app on iOS 11 I get the autofill option on top of t

20条回答
  •  天命终不由人
    2020-11-28 04:34

    iOS 11 & 12 & 13 - Swift 4.2 & 5 (Updated):

    if #available(iOS 12, *) {
        // iOS 12 & 13: Not the best solution, but it works.
        passwordTextField.textContentType = .oneTimeCode
    } else {
        // iOS 11: Disables the autofill accessory view. 
        // For more information see the explanation below.
        emailTextField.textContentType = .init(rawValue: "")
        passwordTextField.textContentType = .init(rawValue: "")
    }
    

    iOS 11 explanation:

    Make sure you setup all of your UITextField objects like this.

    If you have for example an UITextField object where the user must enter his email address and another one where the user must enter his password assign UITextContentType("") to both of their textContentType property. Otherwise it will not work and the autoFill accessory view will still be shown.

提交回复
热议问题