简体   繁体   中英

How to Send Text in an UIInputViewController

so I've got the following code to insert text:

func insert(text: String) {
    (textDocumentProxy as UIKeyInput).insertText(text)
}

But how do I actually get it to send to the chat window?

If you are looking to access all the text entered in the UIInputViewController , the following code may help:

var totalText = "" // complete text entered

if let before: String = self.textDocumentProxy.documentContextBeforeInput {
   totalText += before
}

if let after: String = self.textDocumentProxy.documentContextAfterInput {
   totalText += after
}

Now that you have complete text entered, you can send it to chat window. There are some limitations here which I can share if this is what you're looking for. Please let me know

Edit

To send text to whatsapp , you need to press send button which is outside the custom keyboard extension . If you want to enter text into the UITextView of whatsapp , it is pretty straightforward to do so. But, the custom keyboard extension can't control the send button of whatsapp

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM