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

后端 未结 1 887
长情又很酷
长情又很酷 2021-02-05 20:45

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 when

相关标签:
1条回答
  • 2021-02-05 21:46

    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: @""];
        }
    }
    
    0 讨论(0)
提交回复
热议问题