我正在构建一个 iOS cordova 应用程序,它只需要 UIKeyboardTypeASCIICapable
键盘类型,仅用于 html 输入类型文本,这是为了防止输入汉字。
了解这可以在 iOS 原生 UITextField
上通过将键盘类型设置为 UIKeyboardTypeASCIICapable
来实现。
还了解到我能够使用 javascript 正则表达式来阻止中文字符。
但我正在寻找的是防止通过 QuickType 进行键盘切换。
请让我知道任何需要引用的代码。
最佳答案
设法更改我的 cordova 应用程序的键盘类型,引用 iOS use UIKeyboardTypeDecimalPad in UIWebView form input 的一个问题
这是代码,
NSString* UIClassString = [@[@"UI", @"Web", @"Browser", @"View"] componentsJoinedByString:@""];
NSString* UITraitsClassString = [@[@"UI", @"Text", @"Input", @"Traits"] componentsJoinedByString:@""];
IMP newImp = imp_implementationWithBlock(^(id _s) {
return UIKeyboardTypeASCIICapable;
// return UIKeyboardTypeDefault;
});
for (NSString* classString in @[UIClassString, UITraitsClassString]) {
Class c = NSClassFromString(classString);
Method m = class_getInstanceMethod(c, @selector(keyboardType));
if (m != NULL) {
method_setImplementation(m, newImp);
} else {
class_addMethod(c, @selector(keyboardType), newImp, "l@:");
}
}
代码需要在应用启动时或显示键盘之前运行。
这又是一个问题(在这里发布了一个问题 Cordova Application - Event Listener for before keyboard show / open)。对于其他 html 输入类型,例如 tel
、 number
、 email
等。键盘将默认为仅 UIKeyboardTypeASCIICapable
。
您可能需要一个事件监听器来监听正在显示的键盘并检测元素类型,并相应地更改键盘类型。在这段代码下
IMP newImp = imp_implementationWithBlock(^(id _s) {
return UIKeyboardTypeASCIICapable;
// return UIKeyboardTypeDefault;
});
关于ios - Cordova 应用程序 - 具有 UIKeyboardTypeASCIICapable/ASCII Capable 的 Html 输入文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57607409/