Class

MSMessage

Use the MSMessage class to create interactive message objects. To create a message that can be updated by the conversation’s participants, instantiate a message with a session using the init(session:) method. Otherwise, instantiate the message using the init() method.

Overview

Setting Required Properties

Before using an MSMessage object, you must set both its url and layout properties:

  • Encode app-specific data in the message’s url property. Use the NSURLComponents class to easily access, set, or modify a URL’s component parts.

  • Define the message’s appearance using the message’s layout property. Use the MSMessageTemplateLayout class to set an image, video, or audio file for the message. This class also defines a number of text elements, such as the message’s title, subtitle, caption, and subcaption.

Handling Messages

When a message from an iMessage app arrives, the following situations generate their corresponding events:

  • The message is associated with an existing session. The previous message is moved to the bottom of the transcript and updated with the new message’s content.

  • Your iMessage app is running. The system calls your MSMessagesAppViewController object’s didReceive(_:conversation:) method.

When a user selects a message from an iMessage app, the behavior varies depending on where the message appears:

  • iOS device with the iMessage app installed.

  • iOS device without the iMessage app installed. The system opens the App Store for iMessage and prompts the user to install the iMessage app.

  • macOS. The system attempts to open the URL. If the system does not recognize the URL, it displays an error message.

Topics

Creating Messages

init()

Initializes a new message that is not part of a session.

init(session: MSSession)

Initializes a new message that is part of the provided session.

Message Properties

var accessibilityLabel: String?

A localized string that describes the message.

var error: Error?

An error object describing why the system failed to send the message.

var layout: MSMessageLayout?

A layout object that defines the message’s appearance.

var senderParticipantIdentifier: UUID

A UUID identifying the participant that sent the message.

var session: MSSession?

The session that this message belongs to.

var shouldExpire: Bool

A Boolean value that determines whether the message should expire after being read.

var summaryText: String?

A succinct description of the message.

var url: URL?

A URL that encodes data to be transmitted with the message.

Instance Properties

Relationships

Inherits From

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software