How to detect from iOS keyboard extension that a textfield is cleared via actions like hitting “Send” in iMessage?

In my iOS keyboard app, I currently have a text suggestions bar much like the default iOS 8 Keyboard’s suggestion bar. I would like to clear all text on the suggestion bar whenever the user does something that clears the text field (for example, when someone hits “Send” on iMessage or Whatsapp,).

As hitting “Send” is not a keystroke, I was wondering if there is way to detect from the keyboard when a textfield is cleared.

  • Simple way to identify iOS user agent in a jQuery if/then statement?
  • NSPredicate 'The left hand side for an ALL or ANY operator must be either an NSArray or NSSet'
  • Get all E-Mail addresses from contacts (iOS)
  • When should I compare an optional value to nil?
  • How to create and save EKCalendar on ios 6
  • Adding space/padding to a UILabel
  • I have tried detecting empty text "" or new line "\n", but so far this has not worked.

    Edit: I do know that this is possible through 3rd party iOS Keyboard, as seen the case here (this is from Themeboard)

    Before hitting send, note the text in the suggestion bar.
    Before hitting send

    Immediately after hitting “send”. The suggestion bar is cleared.
    After hitting send

    Solutions Collect From Internet About “How to detect from iOS keyboard extension that a textfield is cleared via actions like hitting “Send” in iMessage?”

    When the send button is pressed in Messages, the textDidChange: callback will be called on your UIInputViewController subclass. At that point, both the documentContextAfterInput and documentContextBeforeInput properties of your UIInputViewController subclass’s textDocumentProxy property will be nil or the empty string. While you don’t know why the textfield was cleared, you can probably infer for most cases where this occurs that you should clear your current next word prediction.

    - (void)textDidChange:(id<UITextInput>)textInput
    {
        if ((!self.textDocumentProxy.documentContextBeforeInput && !self.textDocumentProxy.documentContextAfterInput) || ([self.textDocumentProxy.documentContextBeforeInput isEqualToString:@""] && [self.textDocumentProxy.documentContextAfterInput isEqualToString:@""])){
            //Implement code to clear the banner
            [self.keyboard.lblBanner setText: @""];
        }
    }