<!--
{
  "availability" : [
    "iOS: 10.0.0 -",
    "iPadOS: 10.0.0 -",
    "macCatalyst: 13.1.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Messages",
  "identifier" : "/documentation/Messages/MSSession",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Messages"
    ],
    "preciseIdentifier" : "c:objc(cs)MSSession"
  },
  "title" : "MSSession"
}
-->

# MSSession

A session object used to create and update messages.

```
class MSSession
```

## Overview> Note:
> The ``doc://com.apple.messages/documentation/Messages/MSSession`` class does not declare any instance methods or properties. iMessage apps use ``doc://com.apple.messages/documentation/Messages/MSSession`` objects to identify and track updatable messages.

[`MSMessage`](/documentation/Messages/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.
- If the previous message has a non-`nil` [`summaryText`](/documentation/Messages/MSMessage/summaryText) property, the Messages app creates a summary message from the text and inserts it in the message’s previous location.

### Create 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`](/documentation/Messages/MSMessage) class’s [`url`](/documentation/Messages/MSMessage/url) property.
- A new layout object that describes the initial message’s appearance. For more information, see the [`MSMessage`](/documentation/Messages/MSMessage) class’s [`layout`](/documentation/Messages/MSMessage/layout) property.
- A string that describes the message’s current state. For more information, see the [`MSMessage`](/documentation/Messages/MSMessage) class’s [`summaryText`](/documentation/Messages/MSMessage/summaryText) property.

1. Instantiate a new [`MSSession`](/documentation/Messages/MSSession) object by calling its <doc://com.apple.documentation/documentation/ObjectiveC/NSObject-swift.class/init()> method.
2. Instantiate a new [`MSMessage`](/documentation/Messages/MSMessage) object by calling its [`init(session:)`](/documentation/Messages/MSMessage/init(session:)) method and passing the session object. Set the message’s [`url`](/documentation/Messages/MSMessage/url), [`layout`](/documentation/Messages/MSMessage/layout), and [`summaryText`](/documentation/Messages/MSMessage/summaryText) properties.
3. Send the message by calling the conversation’s [`insert(_:completionHandler:)`](/documentation/Messages/MSConversation/insert(_:completionHandler:)-3g248) 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.

### Update Messages

Use the following workflow to receive and update a message.

1. When the user taps on one of your [`MSMessage`](/documentation/Messages/MSMessage) entries, the conversation’s [`selectedMessage`](/documentation/Messages/MSConversation/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`](/documentation/Messages/MSMessage/url) property, and present it to the user.
   For more information on receiving messages, see [`MSMessage`](/documentation/Messages/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`](/documentation/Messages/MSMessage) class’s [`url`](/documentation/Messages/MSMessage/url) property.
- A new layout object that describes the updated message’s appearance. For more information, see the [`MSMessage`](/documentation/Messages/MSMessage) class’s [`layout`](/documentation/Messages/MSMessage/layout) property.
- A string that describes the message’s current state. For more information, see the [`MSMessage`](/documentation/Messages/MSMessage) class’s [`summaryText`](/documentation/Messages/MSMessage/summaryText) property.

1. Instantiate a new [`MSMessage`](/documentation/Messages/MSMessage) object by calling its [`init(session:)`](/documentation/Messages/MSMessage/init(session:)) method and passing the currently selected message’s [`MSSession`](/documentation/Messages/MSSession) object. Set the message’s [`url`](/documentation/Messages/MSMessage/url), [`layout`](/documentation/Messages/MSMessage/layout), and [`summaryText`](/documentation/Messages/MSMessage/summaryText) properties.
2. Send the updated message by calling the conversation’s [`insert(_:completionHandler:)`](/documentation/Messages/MSConversation/insert(_:completionHandler:)-3g248) method.

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

## Relationships

### Conforms To

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`NSSecureCoding`](/documentation/Foundation/NSSecureCoding)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`Equatable`](/documentation/Swift/Equatable)

[`NSCoding`](/documentation/Foundation/NSCoding)

[`CVarArg`](/documentation/Swift/CVarArg)

[`Hashable`](/documentation/Swift/Hashable)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)