How does keyboard extension know the document proxy has changed?
IOS keyboard extensions are subclasses of the class UIInputViewController
and have the ability to textDocumentProxy
interact with the underlying document. The object textDocumentProxy
provides some important features of the document, such as the type of autocapitalization. The question is, how is the keyboard expansion known when changing the underlying document?
For example, when I click to create a new message in the Messages app, the To field uses different input tags than the message body input field. But since the keyboard does not disappear when the focus switches from one field to another, the proxy object of the text document changes on the fly. Can the keyboard expansion notice such a change?
Ive tried to view properties textDocumentProxy
and [[self textDocumentProxy] autocapitalizationType]
through KVO but it doesn't work. Checking the property autocapitalizationType
with a timer shows the change, but obviously Id wants to avoid polling.
source to share
My UIInputViewController
supports the protocol UITextInput
that the method has textDidChange
. From textDidChange
what I compare self.textDocumentProxy
with my own property self.currentTextProxy
. When they differ from each other, I update self.currentTextProxy
and then update my GUI based on self.textDocumentProxy
s UITextInputTraits
.
source to share