This chapter has mostly focused on user interface-related aspects of iMessage apps. When you create an iMessage app, your app will sooner or later have to send a message. To do this, you use the MSMessage and MSSession objects. In addition to messages and sessions, the MSConversation class represents the conversation context that your extension exists in. These three classes together allow you to send messages, identify recipients in conversations, and even update or collapse existing messages in the messages transcript.
When an iMessage extension is activated, willBecomeActive(with:) is called in MessagesViewController. This method receives an instance of MSConversation that you can use to send messages, stickers, and even attachments. More importantly, the conversation contains unique identifiers for participants in the conversation and the currently selected message.
The localParticipantIdentifier and remoteParticipantIdentifier properties identify the current user of your app or the person who is sending messages with your app, and the recipients of these messages, respectively. Note that these identifiers are unique to your app so you can't use this identifier to identify users across different iMessage apps. Also, these identifiers can change if the user uninstalls and then reinstalls your app. The participant identifiers are mostly meant to identify users in a group conversation.
The selectedMessage property is only set if your extension was launched due to a user tapping on a message that was sent by your extension. This is especially useful if you're building an app that sends multiple messages that build upon each other. In Apple's 2016 WWDC talk, iMessage Apps and Stickers, Part 2, they demonstrated an ice-cream designer app. Each user designs a part of the ice cream and selectedMessage is used in combination with MSSession to collapse old messages so the message history does not get polluted with old pictures of ice creams. You will learn how to use this session in a bit. First, let's have a look at MSMessage to see how you can create messages.