insertText(_:completionHandler:)
Inserts text into the Messages app’s input field.
Declaration
func insertText(_ text: String, completionHandler: (@Sendable ((any Error)?) -> Void)? = nil)func insertText(_ text: String) async throwsParameters
- text:
The text to be inserted.
- completionHandler:
A block that is called as soon as the insertion is complete. This block is passed the following parameter:
- error
An error object. If an error occurred, this object contains information about the error; otherwise, it is set to
nil.
Mentioned in
Discussion
Use this method to insert text into the Message app’s input field. Users can then send the text by tapping Send. iMessage apps suport this method only in the MSMessagesAppPresentationContext.messages context. If called in the MSMessagesAppPresentationContext.media context, the method fails with an MSMessageErrorCode.apiUnavailableInPresentationContext error.
This method operates asynchronously. Although the method returns immediately, the actual work is deferred and performed in the background. As soon as the attachment is inserted, the system calls the completion block on a background queue.