Instance Method


Inserts a message object into the Messages app’s input field.


- (void)insertMessage:(MSMessage *)message completionHandler:(void (^)(NSError *error))completionHandler;



The message object to be inserted.


A block that is called as soon as the insertion is complete. This block is passed the following parameter:


An error object. If an error occurred, this object contains information about the error; otherwise, it is set to nil. The system validates the message before inserting it. Errors occur if the message is invalid. Otherwise, the message is inserted into the Messages app’s input field.


Use this method to insert an MSMessage object into the Message app’s input field. Users can then send the message by tapping Send. iMessage apps suport this method only in the MSMessagesAppPresentationContextMessages context. If called in the MSMessagesAppPresentationContextMedia context, the method fails with an MSMessageErrorCodeAPIUnavailableInPresentationContext error.

The message object’s appearance is determined by its layout property. The message can contain app-specific data and can be associated with a session, letting other participants update the message. For more information, see MSMessage.

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.

Subsequent calls to this method replace any existing message in the input field.

If the message was initialized using the session from an existing message, a new message is not added to the transcript. Instead, the system takes the following steps as soon as the user sends the message:

  1. The system moves the existing message to the bottom of the conversation transcript.

  2. It updates the message with the new content.

See Also

Inserting Content into the Input Field

- insertAttachment:withAlternateFilename:completionHandler:

Inserts an attachment into the current context.

- insertSticker:completionHandler:

Inserts a sticker into the current context.

- insertText:completionHandler:

Inserts text into the Messages app’s input field.