Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS disable Quicktype Keyboard programmatically on UIWebBrowserView

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!

like image 414
BorisR Avatar asked Aug 06 '15 11:08

BorisR


2 Answers

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.

like image 97
TomSwift Avatar answered Sep 17 '22 12:09

TomSwift


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.

like image 27
Ponf Avatar answered Sep 16 '22 12:09

Ponf