【问题标题】:iOS 13 only occasionally suggests a strong password after switching from previous textfield从以前的文本字段切换后,iOS 13 仅偶尔会建议使用强密码
【发布时间】:2020-05-12 08:17:58
【问题描述】:

我正在努力为 iOS 13 上的 UITextField 添加强密码生成。尽管将 textContentType 添加到 .newPassword,但它根本不适用于我的主要新密码字段。但是,只有当我在主密码字段之后选择它时,它才适用于我的确认密码字段。 这是这些文本字段的设置,发生在控制器的 init 中。

    valueTextfield.font = .boldSystemFont(ofSize: 28)
    valueTextfield.autocapitalizationType = .none
    valueTextfield.autocorrectionType = .no
    valueTextfield.textColor = .black
    valueTextfield.textAlignment = .center
    valueTextfield.borderStyle = .none
    valueTextfield.tintColor = .primary
    valueTextfield.sizeToFit()valueTextfield.textContentType = .newPassword
    valueTextfield.placeholder = "Password".localized

    confirmationTextField.font = .boldSystemFont(ofSize: 28)
    confirmationTextField.textColor = .black
    confirmationTextField.textAlignment = .center
    confirmationTextField.autocapitalizationType = .none
    confirmationTextField.autocorrectionType = .no
    confirmationTextField.textContentType = .newPassword
    confirmationTextField.borderStyle = .none
    confirmationTextField.tintColor = .primary
    confirmationTextField.placeholder = "Confirm".localized

即使将文本字段添加到空白控制器也无济于事。这是 iOS 13 的错误吗?

【问题讨论】:

    标签: ios swift iphone passwords uitextfield


    【解决方案1】:

    显然,我希望自动生成密码的工作方式目前是不可能的。 要使强密码建议起作用,用户名文本字段应与密码文本字段在同一屏幕上。 这很奇怪,但在研究了 Twitter 等应用程序后,我发现它们都没有针对单个密码文本字段的强密码建议。不知道是bug还是功能。 我将不得不手动重新实现此功能。

    【讨论】:

      【解决方案2】:

      确保您已正确设置UITextField 的这三个属性,以便密码自动填充工作:

      textField.isSecureTextEntry = true
      textField.autocapitalizationType = .none
      textField.textContentType = .password
      

      最重要的是,启用密码自动填充: Settings > Passwords & Accounts > AutoFill Passwords

      【讨论】:

      • 感谢您的回复,不幸的是,这没有帮助,如果我在控制器中有一个文本字段,就没有机会获得强密码建议
      • 我想你也应该在一些文本字段上也有.textContentType = .username
      • 我确实将它放在导航堆栈中位于此控制器之前的控制器中,但这无济于事
      • 我知道使用textContentType 有时可能会让人感到困惑。例如。当自动填充在某些设备上不起作用而在其他设备上起作用时,我遇到了问题。想不通为什么。事实证明,如果您更改键盘类型,自动填充可能会关闭。
      猜你喜欢
      • 2019-05-03
      • 2021-08-02
      • 2017-09-20
      • 2019-03-30
      • 1970-01-01
      • 2020-03-21
      • 1970-01-01
      • 2012-01-09
      • 2012-06-28
      相关资源
      最近更新 更多