Composing a message

The MSMessage class encapsulates all the information that is contained inside a message. When you initialize a message, you can initialize it with or without a session. If you instantiate a message with a session, other messages that are attached to this session will be collapsed to only show the message's summaryText. The summary is supposed to be a short, clear description of the message so that, even when the message is collapsed, the message still makes sense.

If possible, you should always aim to attach a URL and accessibilityLabel to your messages, depending on the types of message your app will send. If you're sending plain text messages like The Daily Quote will, you don't need an accessibility label since iOS can simply read the text message out loud for users with accessibility needs. The URL property is mainly used by platforms that don't support iMessage extensions, such as macOS. Attaching a URL makes sure that users can still navigate to your content online. When you're sending plain text, this isn't an issue.

Finally, if you're sending a message that has media attached to it, you should make use of the MSMessageTemplateLayout class. MSMessage has a layout property that can be set to an instance of MSMessageTemplateLayout. The message layout template is highly configurable. You can assign an image or media to it, set a caption, an image title, a sub-caption, and more. Messages will make sure that your layout looks good and is laid out nicely depending on the information you set.

If you set both a media URL and an image on your message layout, the image will be used and the other media items are ignored. Any images you add should be 300x300 @3x. Avoid rendering text on the image as the scaling on different devices might degrade the quality of your image and render the text illegible. Instead, use the image title and image subtitle properties from the message layout object.

An MSMessage instance is always intended to either have some form of media associated with it or to be interactive.