“您要保存此密码吗?"对话框阻止键盘出现 [英] "Would you like to save this password " dialog blocks keyboard from appearing

查看:134
本文介绍了“您要保存此密码吗?"对话框阻止键盘出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您是否想保存此密码"对话框出现问题.当它弹出并且用户回到主屏幕并返回到应用程序时,对话框消失,并且当触摸文本框时他不能举起键盘.在iOS 13上,它唯一的工作方式"是这样.在iOS 12上,它可以正常工作,因为当用户返回到应用程序时,对话框仍然存在.然后,他可以保存密码或不立即点击并开始输入.任何想法如何解决这个问题?它可能是某种iOS 13错误.

I have problem with "Would you like to save this password" dialog. When it pop-up and user go to home screen and back to app, dialog disappears and he is not able to raise keyboard when to touch in to textfield. Its only "working" like this on iOS 13. On iOS 12 it is working OK, because when user come back to app, dialog is still there. Then he can save password or tap not now and start typing. Any ideas how to solve this? Its probably some kind of iOS 13 bug.

推荐答案

问题

OP写道:如果您启用了关联域,则在iOS 13中使用自动填充功能,那么您会得到一个UIAlertController,要求您保存或更新密码,请参见 https://developer.apple.com/videos/play/wwdc2017/206/了解更多信息.

As OP writes: if you have associated domains enabled, autofill feature is used in iOS 13, then you get a UIAlertController which asks you to save or update the password, see https://developer.apple.com/videos/play/wwdc2017/206/ for more information.

iOS 13的问题在于,如果用户在点击更新密码"或不立即"按钮之前将应用程序置于后台,则在切换回前台后不再显示文本字段的键盘,看到这里:

The problem with iOS 13 is that if the user puts applications in the background before tapping either the 'Update Password' or the 'Not Now' button, the keyboard for text fields is no longer shown after switching back to the foreground, see here:

由于它是操作系统的系统对话框,因此您无法在进入后台之前以编程方式将其关闭.

Since it is a system dialog of the operating system you can't dismiss it programmatically before going background.

因此,在苹果公司解决此问题之前,您可以:

So until this is fixed by Apple one can either:

  • 使用SecRequestSharedWebCredential/SecAddSharedWebCredential的变通办法
  • 或不使用该功能
  • 或忽略边缘情况

解决方法

一种解决方法可能是:

  • 请勿在iOS 13上使用新的自动填充功能
  • 改为使用SecRequestSharedWebCredential/SecAddSharedWebCredential

然后看起来像这样:

请勿使用自动填充

为了不使用新的自动填充功能,应设置textContentType,因此不可以:

So that the new autofill is not used, the textContentType should not be set, therefore no:

userTextField.textContentType = .username
passwordTextField.textContentType = .password

也不要将isSecureTextEntry设置为true.实际上,这意味着您需要自己的机制来隐藏密码文本字段的条目.有关建议,请参见 iOS 11禁用密码自动填充附件视图选项?

Also don't set isSecureTextEntry to true. This means in practice that you need your own mechanism, to hide the entry for the password textfield. For suggestions see e.g. iOS 11 disable password autofill accessory view option?

SecRequestSharedWebCredential

在登录页面上,可以在viewDidLoad中使用

On the login page one could use in viewDidLoad:

if #available(iOS 13, *) {
    requestCredentials()
} else {
    userTextField.textContentType = .username
    passwordTextField.textContentType = .password
}

private func requestCredentials() {
    SecRequestSharedWebCredential("software7.com" as CFString, nil, {
        credentials, error -> Void in
        guard error == nil else { return }
        guard let credentials = credentials, CFArrayGetCount(credentials) > 0 else { return }
        let unsafeCredential = CFArrayGetValueAtIndex(credentials, 0)
        let credential: CFDictionary = unsafeBitCast(unsafeCredential, to: CFDictionary.self)
        let dict: Dictionary<String, String> = credential as! Dictionary<String, String>
        let username = dict[kSecAttrAccount as String]
        let password = dict[kSecSharedPassword as String]

        DispatchQueue.main.async {
            self.userTextField.text = username;
            self.passwordTextField.text = password;
        }
    });
}

SecAddSharedWebCredential

在第二个ViewController的viewDidLoad中,可以使用:

In viewDidLoad of the second ViewController one could use:

if #available(iOS 13, *) {
    updateCredentials()
} else {
    //works automatically with autofill
}

private func updateCredentials() {
    SecAddSharedWebCredential("software7.com" as NSString as CFString,
                              self.userName as NSString as CFString,
                              self.password as NSString as CFString,
                              { error in if let error = error { print("error: \(error)") }
    })
}

这看起来不像iOS 13的自动填充功能,但是它们允许您在用户转为bg/fg时继续提供自动填充和共享凭据,从而继续使用键盘.修复错误后,可以删除此解决方法.

This doesn't look as good as the autofill feature of iOS 13, but they allow you to continue using the keyboard when the user goes bg/fg by still offering autofill and shared credentials. Once the bug is fixed, this workaround can be removed.

这篇关于“您要保存此密码吗?"对话框阻止键盘出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆