Search code examples
iphoneiosipaduiwebviewuikeyinput

How to use `UIKeyInput` protocol with `UIWebView` control?


How to use UIKeyInput protocol with UIWebView control?

(I'm trying to fix backspace issue: it works on external keyboard, but doesn't work on iOS keyboard for more than 1 removed char, and it works after a char was entered on both keyboards.)


Solution

  • The problem with UIWebView is that it is a very restricted container view of UIWebDocumentView, a private class, which is the one you actually need to subclass in order to implement what you need. Well, it's possible, but it is very grey area. Our app does some magic with this "special" view and it is on the app store.

    Your only solution is to dynamically change the subclass of this UIWebDocumentView instance with a class of your own, which will dynamically become a subclass of the UIWebDocumentView class. In this class of your own, you will be able to implement the protocol methods.

    If this scares you, then by all means you should not attempt. If you are in for adventure, it's not as bad as it sounds (a little Objective C runtime magic). Let me know if you need help.