iOS在UIWebBrowserView上以编程方式禁用Quicktype键盘

iOS在UIWebBrowserView上以编程方式禁用Quicktype键盘,ios,cordova,contenteditable,Ios,Cordova,Contenteditable,我正在为iOS开发PhoneGap应用程序,我需要禁用键盘上的自动预测文本 我发现了许多针对UITextView的解决方案,如下所示: 。。。但PhoneGap应用程序内部有UIWebBrowserView 我还知道用于禁用自动预测的html属性。它们仅适用于常规html输入,但在我的UIWebBrowserView上有contenteditable元素,这是文本编辑器的可编辑区域(在我的例子中是CKEditor) 那么,有没有办法在iOS上以编程方式禁用contenteditable元

我正在为iOS开发PhoneGap应用程序,我需要禁用键盘上的自动预测文本

我发现了许多针对
UITextView
的解决方案,如下所示:

。。。但PhoneGap应用程序内部有
UIWebBrowserView

我还知道用于禁用自动预测的html属性。它们仅适用于常规html输入,但在我的
UIWebBrowserView
上有
contenteditable
元素,这是文本编辑器的可编辑区域(在我的例子中是CKEditor)


那么,有没有办法在iOS上以编程方式禁用contenteditable元素的自动预测功能


非常感谢您的帮助

我最近在一个托管UIWebView的本机应用程序(不是PhoneGap)中遇到了这个问题,但无法通过更改HTML来解决。我建议向苹果公司提交一个bug

我能够用一个相当复杂的方案强制键盘显示sans QuickType,我确信这不会通过应用商店指南:

1) 注意
UIKeyboardWillShowNotification
通知

2) 当键盘出现时,找到第一响应者-这将是
UIWebView中的一些视图

3) 动态地对该视图进行子类化,以提供
textInputRaits
方法的替代实现(该方法返回
uitRaits
一致性对象)。将此返回对象上的
autocorrectionType
设置为
UITextAutocorrectionTypeNo

4) 在第一响应者视图上调用
reloadInputViews
——两次


我意识到所有这些都不可能帮助你或解决你的具体问题,但也许它会帮助别人。

方法滑动可能会有所帮助

1.创建目录:UITextView+CloseQuickType.h&UITextView+CloseQuickType.m

2.下载

3.UITextView+CloseQuickType.m:

#import "UITextView+CloseQuickType.h"
#import <objc/runtime.h>
#import "JRSwizzle.h"
@implementation UITextView (CloseQuickType)
+ (void)load {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        //exchange init methods
        [self jr_swizzleMethod:@selector(init) withMethod:@selector(init_) error:nil];
        [self jr_swizzleMethod:@selector(initWithFrame:) withMethod:@selector(initWithFrame_:) error:nil];
        [self jr_swizzleMethod:@selector(initWithCoder:) withMethod:@selector(initWithCoder_:) error:nil];
    });
}
#pragma mark - myInitMethods
- (instancetype)init_ {
    self = [self init_];
    if (self) {
        self.autocorrectionType = UITextAutocorrectionTypeNo;
    }
    return self;
}
- (instancetype)initWithFrame_:(CGRect)frame {
    self = [self initWithFrame_:frame];
    if (self) {
        self.autocorrectionType = UITextAutocorrectionTypeNo;
    }
    return self;
}
- (instancetype)initWithCoder_:(NSCoder *)aDecoder {
    self = [self initWithCoder_:aDecoder];
    if (self) {
        self.autocorrectionType = UITextAutocorrectionTypeNo;
    }
    return self;
}
@end

要更改默认设置但在Xcode7、ios9中崩溃,我找到的唯一方法是使用私有API:

UIWebBrowserView *browserView = _myBrowserView;

NSString *spellChecking =@"setContinuousSpellCheckingEnabled:";
SEL enableSpellCheckingSelector = NSSelectorFromString(spellChecking);

NSMethodSignature* signature = [[browserView class] instanceMethodSignatureForSelector:enableSpellCheckingSelector];
if (!signature)
    return;
NSInvocation* invocation = [NSInvocation invocationWithMethodSignature:signature];
[invocation setTarget:browserView];
[invocation setSelector:enableSpellCheckingSelector];
[invocation setArgument:&enabled atIndex:2];
[invocation invoke];
它在iOS7和iOS8对我有效


然而,有了这样的把戏,你可能无法通过苹果公司的审查。

你找到了解决这个问题的办法吗?在contenteditable上是不可能的elements@Robin还没有找到解决办法。但由于此功能对应用程序至关重要,我们使用了复杂的解决方法-创建本机文本编辑器(iOS版RichTextEditor)并将其绘制在WebView上方。当应用程序的某些部分应该位于本机编辑器(例如模态对话框)之上时,我们将本机编辑器替换为填充本机编辑器内容的
div
元素。
[[UITextView appearance] setAutocorrectionType:UITextAutocorrectionTypeNo];
UIWebBrowserView *browserView = _myBrowserView;

NSString *spellChecking =@"setContinuousSpellCheckingEnabled:";
SEL enableSpellCheckingSelector = NSSelectorFromString(spellChecking);

NSMethodSignature* signature = [[browserView class] instanceMethodSignatureForSelector:enableSpellCheckingSelector];
if (!signature)
    return;
NSInvocation* invocation = [NSInvocation invocationWithMethodSignature:signature];
[invocation setTarget:browserView];
[invocation setSelector:enableSpellCheckingSelector];
[invocation setArgument:&enabled atIndex:2];
[invocation invoke];