本机 UITextField 安全文本输入强制英语(美国)键盘
Native UITextField Secure Text Entry forces English (US) keyboard
我有一个非常简单的登录页面(登录名+密码)。
我的用户是法国人,所以他们的键盘是法语 (azerty)。
自 iOS12 起,当他们单击受保护的密码文本字段时,键盘会切换为英语 (qwerty),即使他们的设备上没有安装此键盘。此外,如果他们没有安装此键盘,则无法切换回他们的键盘。
我发现如果我停用安全文本输入,问题就不会出现。
我还尝试以编程方式设置 isSecureTextEntry,但错误出现了。
我正在添加两张屏幕截图,每个文本字段一张。
非常感谢您的宝贵时间和帮助。
Swift 3:
使用 languageCode 和 textInputMode 为 UITextField 创建基础 class。
class BaseTextField: UITextField {
// ru, en, ....
var languageCode: String? {
didSet{
if self.isFirstResponder{
self.resignFirstResponder();
self.becomeFirstResponder();
}
}
}
override var textInputMode: UITextInputMode? {
if let language_code = self.languageCode {
for keyboard in UITextInputMode.activeInputModes {
if let language = keyboard.primaryLanguage {
let locale = Locale.init(identifier: language);
if locale.languageCode == language_code {
return keyboard;
}
}
}
}
return super.textInputMode;
}}
用法:
将您的值(ru、en、...)设置为 languageCode。它将强制更改键盘中的语言环境。
private func textConfigure(textField: UITextField) {
textField.keyboardType = .default
textField.autocapitalizationType = .words
textField.languageCode = "ru"
}
希望对你有帮助。
这确实是一个 iOS 错误 => 在 iOS 12.1
中得到更正
我有同样的问题,在我的情况下,这个错误只出现在注册屏幕上。
原因是 Apple 检查 class/func/parameter 的名称以确定(使用试探法)它是否是 login/register 屏幕并激活自动自动填充密码。
通过在我的代码中将 "register" 替换为 "Patate" ,问题就解决了。
我用一个带有 2 个文本字段(带有一个安全文本条目)和一个名为 "RegisterViewController" 的视图控制器的示例应用重现了这个问题。有了"PatateViewController",我没有问题。
此外,我在控制台中遇到此错误:
[AutoFill] 无法显示 app bundleID 的自动强密码:*** 由于错误:iCloud 钥匙串已禁用
来源:https://developer.apple.com/documentation/security/password_autofill
希望您能找到比重命名代码更好的方法。
我最近在我们的申请中遇到了同样的问题。
问题是 linkApple 的 PasswordAutofill 的新功能。
要绕过这个问题,您可以在您的安全文本字段上应用这段代码
if #available(iOS 12.0, *) {
tfPassword.textContentType = .oneTimeCode
}
这应该可以解决此错误。
这也应该修复此错误:
[AutoFill] Cannot show Automatic Strong Passwords for app bundleID: *** due to error: iCloud Keychain is disabled
Ps:您也可以将此新功能添加到您的应用中。
这是一篇 link 的文章,解释了如何实现这个新功能的过程
Explanation on how to implement password autofill
希望对您有所帮助。
iOS 12.1 为我解决了这个问题。
您还必须将密码文本字段的参数 textContentType
设置为 .oneTimeCode
有同样的问题并通过将 all my textFields textContentType
属性 设置为 UITextContentType.oneTimeCode
.
解决了
当然,oneTimeCode
现在没用了,因为它无处不在...
bug 越糟糕,解决方案就应该越糟糕,我的意思是 Apple 的工作多么蹩脚。
我的解决方案是强制关注密码字段,然后关注第一个字段,在我的例子中是用户名字段。
- (void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self.passwordTextField becomeFirstResponder];
[self.usernameTextField becomeFirstResponder];
}
为了以防万一,我通过简单地将其添加到我的主要 viewController 来更正此问题:
func passwordSignUpViewController(forAuthUI authUI: FUIAuth, email: String, requireDisplayName: Bool) -> FUIPasswordSignUpViewController {
return CustomPasswordSignUpViewController(authUI: authUI, email: email, requireDisplayName: true)
}
并且我创建了 FUIPasswordSignUpViewController 的子类
import Foundation
import FirebaseUI
class CustomPasswordSignUpViewController : FUIPasswordSignUpViewController, UITextFieldDelegate {
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?, authUI: FUIAuth, email: String?, requireDisplayName: Bool) {
super.init(nibName: "FUIPasswordSignUpViewController", bundle: nibBundleOrNil, authUI: authUI, email: email, requireDisplayName: requireDisplayName)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override func viewDidLoad() {
super.viewDidLoad()
}
func textFieldDidBeginEditing(_ textField: UITextField) {
if #available(iOS 12.0, *) {
textField.textContentType = .oneTimeCode
}
}
}
现在 Swiftui 中的相同解决方案:
TextField("placeholder",text: $YourTextBinding)
.textContentType(.oneTimeCode)
.keyboardType(.default)
只需添加:
.textContentType(.oneTimeCode)
.keyboardType(.default)
到 TextField
或 SecureField
。
希望对您有所帮助!
当我将 keyboardType 设置为 "numeric-pad" 时,我在 React Native 中遇到了同样的问题。
由于 info.plist
文件中设置的默认语言,这是本机 IOS 问题。
我在这里找到了解决方案:https://github.com/facebook/react-native/issues/27972
删除这两行以取消设置默认语言:
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
您也可以将 <string>en</string>
修改为 <string>fr</string>
,但是您将遇到同样的问题,英语用户将切换到 azerty 键盘:/
就我而言,以下行解决了我的问题。
textField.textContentType = .newPassword
我有一个非常简单的登录页面(登录名+密码)。
我的用户是法国人,所以他们的键盘是法语 (azerty)。
自 iOS12 起,当他们单击受保护的密码文本字段时,键盘会切换为英语 (qwerty),即使他们的设备上没有安装此键盘。此外,如果他们没有安装此键盘,则无法切换回他们的键盘。
我发现如果我停用安全文本输入,问题就不会出现。
我还尝试以编程方式设置 isSecureTextEntry,但错误出现了。
我正在添加两张屏幕截图,每个文本字段一张。
非常感谢您的宝贵时间和帮助。
Swift 3:
使用 languageCode 和 textInputMode 为 UITextField 创建基础 class。
class BaseTextField: UITextField {
// ru, en, ....
var languageCode: String? {
didSet{
if self.isFirstResponder{
self.resignFirstResponder();
self.becomeFirstResponder();
}
}
}
override var textInputMode: UITextInputMode? {
if let language_code = self.languageCode {
for keyboard in UITextInputMode.activeInputModes {
if let language = keyboard.primaryLanguage {
let locale = Locale.init(identifier: language);
if locale.languageCode == language_code {
return keyboard;
}
}
}
}
return super.textInputMode;
}}
用法:
将您的值(ru、en、...)设置为 languageCode。它将强制更改键盘中的语言环境。
private func textConfigure(textField: UITextField) {
textField.keyboardType = .default
textField.autocapitalizationType = .words
textField.languageCode = "ru"
}
希望对你有帮助。
这确实是一个 iOS 错误 => 在 iOS 12.1
中得到更正我有同样的问题,在我的情况下,这个错误只出现在注册屏幕上。
原因是 Apple 检查 class/func/parameter 的名称以确定(使用试探法)它是否是 login/register 屏幕并激活自动自动填充密码。 通过在我的代码中将 "register" 替换为 "Patate" ,问题就解决了。
我用一个带有 2 个文本字段(带有一个安全文本条目)和一个名为 "RegisterViewController" 的视图控制器的示例应用重现了这个问题。有了"PatateViewController",我没有问题。
此外,我在控制台中遇到此错误: [AutoFill] 无法显示 app bundleID 的自动强密码:*** 由于错误:iCloud 钥匙串已禁用
来源:https://developer.apple.com/documentation/security/password_autofill
希望您能找到比重命名代码更好的方法。
我最近在我们的申请中遇到了同样的问题。 问题是 linkApple 的 PasswordAutofill 的新功能。
要绕过这个问题,您可以在您的安全文本字段上应用这段代码
if #available(iOS 12.0, *) {
tfPassword.textContentType = .oneTimeCode
}
这应该可以解决此错误。 这也应该修复此错误:
[AutoFill] Cannot show Automatic Strong Passwords for app bundleID: *** due to error: iCloud Keychain is disabled
Ps:您也可以将此新功能添加到您的应用中。 这是一篇 link 的文章,解释了如何实现这个新功能的过程 Explanation on how to implement password autofill
希望对您有所帮助。
iOS 12.1 为我解决了这个问题。
您还必须将密码文本字段的参数 textContentType
设置为 .oneTimeCode
有同样的问题并通过将 all my textFields textContentType
属性 设置为 UITextContentType.oneTimeCode
.
当然,oneTimeCode
现在没用了,因为它无处不在...
bug 越糟糕,解决方案就应该越糟糕,我的意思是 Apple 的工作多么蹩脚。
我的解决方案是强制关注密码字段,然后关注第一个字段,在我的例子中是用户名字段。
- (void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self.passwordTextField becomeFirstResponder];
[self.usernameTextField becomeFirstResponder];
}
为了以防万一,我通过简单地将其添加到我的主要 viewController 来更正此问题:
func passwordSignUpViewController(forAuthUI authUI: FUIAuth, email: String, requireDisplayName: Bool) -> FUIPasswordSignUpViewController {
return CustomPasswordSignUpViewController(authUI: authUI, email: email, requireDisplayName: true)
}
并且我创建了 FUIPasswordSignUpViewController 的子类
import Foundation
import FirebaseUI
class CustomPasswordSignUpViewController : FUIPasswordSignUpViewController, UITextFieldDelegate {
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?, authUI: FUIAuth, email: String?, requireDisplayName: Bool) {
super.init(nibName: "FUIPasswordSignUpViewController", bundle: nibBundleOrNil, authUI: authUI, email: email, requireDisplayName: requireDisplayName)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override func viewDidLoad() {
super.viewDidLoad()
}
func textFieldDidBeginEditing(_ textField: UITextField) {
if #available(iOS 12.0, *) {
textField.textContentType = .oneTimeCode
}
}
}
现在 Swiftui 中的相同解决方案:
TextField("placeholder",text: $YourTextBinding)
.textContentType(.oneTimeCode)
.keyboardType(.default)
只需添加:
.textContentType(.oneTimeCode)
.keyboardType(.default)
到 TextField
或 SecureField
。
希望对您有所帮助!
当我将 keyboardType 设置为 "numeric-pad" 时,我在 React Native 中遇到了同样的问题。
由于 info.plist
文件中设置的默认语言,这是本机 IOS 问题。
我在这里找到了解决方案:https://github.com/facebook/react-native/issues/27972
删除这两行以取消设置默认语言:
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
您也可以将 <string>en</string>
修改为 <string>fr</string>
,但是您将遇到同样的问题,英语用户将切换到 azerty 键盘:/
就我而言,以下行解决了我的问题。
textField.textContentType = .newPassword