Class

MSSession

Use the MSSession class to create and update messages.

Overview

Updatable Messages in the Transcript

MSMessage objects associated with a session receive the following treatment in the transcript:

  • The first time a session is used, the message appears normally in the transcript.

  • If a later message is sent using the same session, the previous message is removed from the transcript. The new message, with the updated content, is added to the bottom of the transcript, as normal.

Creating New, Updatable Messages

Use the following workflow to create a new, updatable message.

  1. Create the following:

    • A new URL that encodes the message’s initial state. For example, you could encode data as key-value pairs in the URL’s query string. For more information, see the MSMessage class’s url property.

    • A new layout object that describes the initial message’s appearance. For more information, see the MSMessage class’s layout property.

    • A string that describes the message’s current state. For more information, see the MSMessage class’s summaryText property.

  2. Instantiate a new MSSession object by calling its init() method.

  3. Instantiate a new MSMessage object by calling its init(session:) method and passing the session object. Set the message’s url, layout, and summaryText properties.

  4. Send the message by calling the conversation’s insert(_:completionHandler:) method. Pass nil for the change description.

The Messages app adds the message to the transcript as soon as the user taps the send button.

Updating Messages

Use the following workflow to receive and update a message.

  1. When the user taps on one of your MSMessage entries, the conversation’s selectedMessage property is changed to the tapped message. Use key-value observing to respond to these changes. Extract the current state from the message’s url property, and present it to the user.

    For more information on receiving messages, see MSMessage.

  2. After the user responds, create the following:

    • A new URL that encodes the updated message state. For example, you could encode the data as key-value pairs in the URL’s query string. For more information, see the MSMessage class’s url property.

    • A new layout object that describes the updated message’s appearance. For more information, see the MSMessage class’s layout property.

    • A string that describes the message’s current state. For more information, see the MSMessage class’s summaryText property.

  3. Instantiate a new MSMessage object by calling its init(session:) method and passing the currently selected message’s MSSession object. Set the message’s url, layout, and summaryText properties.

  4. Send the updated message by calling the conversation’s insert(_:completionHandler:) method.

The Messages app updates the message in the transcript as soon as the user taps the send button.

Relationships

Inherits From