Hide keyboard shortcut for UIWebView in iOS 9

I am developing a PhoneGap application for iOS, and I need to get rid of the new iOS 9 Quick Access Toolbar. Now I do the following in the method - (void)viewDidLoad

 if ([self.webView respondsToSelector:@selector(inputAssistantItem)]) { UITextInputAssistantItem *inputAssistantItem = [self.webView inputAssistantItem]; inputAssistantItem.leadingBarButtonGroups = @[]; inputAssistantItem.trailingBarButtonGroups = @[]; } 

This hides the cancel / redo and copy / paste buttons, but the quick access panel is still displayed on the keyboard and there are navigation buttons on it.

enter image description here

How can I completely get rid of the quick access toolbar.

Thank you for your help!


*** UPDATE 1 ***

Below is my full working code. Hope this can help someone (thanks @Clement answer)

 #import <objc/runtime.h> - (void) hideKeyboardShortcutBar: (UIView *)view { for (UIView *sub in view.subviews) { [self hideKeyboardShortcutBar:sub]; if ([NSStringFromClass([sub class]) isEqualToString:@"UIWebBrowserView"]) { Method method = class_getInstanceMethod(sub.class, @selector(inputAccessoryView)); IMP newImp = imp_implementationWithBlock(^(id _s) { if ([sub respondsToSelector:@selector(inputAssistantItem)]) { UITextInputAssistantItem *inputAssistantItem = [sub inputAssistantItem]; inputAssistantItem.leadingBarButtonGroups = @[]; inputAssistantItem.trailingBarButtonGroups = @[]; } return nil; }); method_setImplementation(method, newImp); } } } - (void)viewDidLoad { [super viewDidLoad]; [self hideKeyboardShortcutBar:self.webView]; } 

This trick will hide the cancel / redo and navigation buttons. But text with auto-prediction will still be displayed on the keyboard. To hide the shortcut bar, fully add the html attributes to your input element

 <input autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" /> 

PS My application is in review now. Still don't know if Apple will approve it.


*** UPDATE 2 ***

My app has been approved by Apple

+7
ios objective-c cordova uiwebview
source share
1 answer

Using the swiziling method, we can remove the keyboard shortcut (works only with ObjC).

  - (void)hideKeyboardShortcutBar { Class webBrowserClass = NSClassFromString(@"UIWebBrowserView"); Method method = class_getInstanceMethod(webBrowserClass, @selector(inputAccessoryView)); IMP newImp = imp_implementationWithBlock(^(id _s) { if ([self.webView respondsToSelector:@selector(inputAssistantItem)]) { UITextInputAssistantItem *inputAssistantItem = [self.webView inputAssistantItem]; inputAssistantItem.leadingBarButtonGroups = @[]; inputAssistantItem.trailingBarButtonGroups = @[]; } return nil; }); method_setImplementation(method, newImp); } 

inputAccessoryView : This property is typically used to attach an additional view to the system keyboard provided for UITextField and UITextView Objects.

Thus, a new implementation block will be launched every time a keyboard appears.

UPDATE

To remove the accessory view from WKWebView , use WKContentView instead of UIWebBrowserView

+6
source share

All Articles