11

I'm developing PhoneGap application for iOS and I need to disable auto predictive text on Keyboard.

I found a lot of solutions for UITextView like these:

Disable iOS8 Quicktype Keyboard programmatically on UITextView

ios8 xcode how to remove QuickType on UIKeyboard ( auto complete / auto suggest )

... but PhoneGap app has UIWebBrowserView inside.

Also I know about html attributes for disabling auto prediction. They work well only for regular html inputs, but I have contenteditable element on my UIWebBrowserView which is an editable area of text editor (CKEditor in my case).

<!-- Does not work -->
<div contenteditable="true" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false">
</div>

So, is there a way to disable autoprediction functionality for contenteditable elements programmatically on iOS?

Greatly appreciate any help!

Community
  • 1
  • 1
BorisR
  • 514
  • 1
  • 4
  • 19
  • Did you find any solution to this? – Robin Andersson Sep 17 '15 at 13:44
  • 1
    not possible on contenteditable elements – jcesarmobile Sep 17 '15 at 14:57
  • 1
    @Robin Not found solution yet. But since this functionality is vitally important for the app we use complicated workaround - create native text editor (RichTextEditor for iOS) and draw it above the WebView. When some part of the app should be above native editor (e.g. modal dialogs), we replace native editor with `div` element filled with native editor content. – BorisR Sep 23 '15 at 13:15

3 Answers3

3

I ran into this issue recently in a native app (not PhoneGap) hosting a UIWebView and was unable to solve it by changing the HTML. I suggest filing a bug with Apple.

I was able to force the keyboard to show sans QuickType with a fairly complicated scheme that I'm sure would NOT pass App Store guidelines:

1) Watch for UIKeyboardWillShowNotification notifications

2) When the keyboard is appearing, find the first responder - this will be some view inside the UIWebView

3) Dynamically subclass this view to provide an alternate implementation of the textInputTraits method (which returns a UITextInputTraits conforming object). Set the autocorrectionType on this returned object to UITextAutocorrectionTypeNo.

4) Call reloadInputViews on the first responder view - twice.

I realize all this doesn't likely help you or solve your specific problem but perhaps it will help someone.

TomSwift
  • 39,369
  • 12
  • 121
  • 149
1

The only way I found - is to use private 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];

It works for me at iOS7 and iOS8.

However, with such trick you may not pass Apple's review.

Ponf
  • 1,190
  • 1
  • 12
  • 28
0

Method Swizzling may help.

1.Create catogory : UITextView+CloseQuickType.h & UITextView+CloseQuickType.m

2.Download jrswizzle at github

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

4.Run application.

PS:I tried

[[UITextView appearance] setAutocorrectionType:UITextAutocorrectionTypeNo];

to change default setting but crashed in Xcode7,ios9.

hstdt
  • 5,652
  • 2
  • 34
  • 34