Contents

didReceive(_:conversation:)

Invoked when the iMessage app receives a new message object.

Declaration

func didReceive(_ message: MSMessage, conversation: MSConversation)

Parameters

  • message:

    The received message object.

  • conversation:

    The conversation that the user is currently viewing in the Messages app.

Mentioned in

Discussion

Override this method to respond to messages that arrive while your extension is active.

If your app displays information about the currently selected message, check the incoming message’s session against the selected message’s session. If they match, update the information displayed in your user interface to represent the most recent message data (see Listing 1).

Listing 1. Updating the current session

override func didReceive(_ message: MSMessage, conversation: MSConversation) {
    // Check to see if the incoming message is part of a session
    if let incomingSession = message.session {
        // Check to see if the incoming session matches the current message’s session
        if incomingSession == conversation.selectedMessage?.session {
            // Update your user interface here...
        }
    }
}

This method is called when a new message arrives while your extension is active. You receive notifications about messages sent using your extension only. You cannot interact with messages from other extensions.

The system does not call this method if the controller’s presentationStyle property is MSMessagesAppPresentationStyle.transcript, or if its presentationContext property is MSMessagesAppPresentationContext.media.

See Also

Tracking Messages