<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: 12.0.0 -",
    "tvOS: 15.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "GroupActivities",
  "identifier" : "/documentation/GroupActivities/GroupSessionMessenger",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Group Activities"
    ],
    "preciseIdentifier" : "s:15GroupActivities0A16SessionMessengerC"
  },
  "title" : "GroupSessionMessenger"
}
-->

# GroupSessionMessenger

An object that transfers app-specific data between the devices joined in a group session.

```
final class GroupSessionMessenger
```

## Overview

Use a `GroupSessionMessenger` object to coordinate your app’s behavior across
the devices attached to a group session. This object leverages the existing
FaceTime communication channel to send app-specific data related
to a SharePlay experience. For example, a movie-watching app might share user
comments or tags while the movie plays.

You create a `GroupSessionMessenger` object directly and use it to send and
receive app data. Create the messenger using an active [`GroupSession`](/documentation/GroupActivities/GroupSession) object,
which manages the underlying communication channel. Store a strong reference
to your `GroupSessionMessenger` object for the lifetime of the session. The following
example shows a custom object for managing a movie-watching experience. The
object stores the GroupSession object associated with the experience and
creates a `GroupSessionMessenger` for sending messages between participants.

```
class CowatchingExperience : ObservableObject {
    let groupSession: GroupSession<Trailer>
    let messenger: GroupSessionMessenger

    init(groupSession: GroupSession<Trailer>, item: Trailer) {
        self.groupSession = groupSession
        self.messenger = GroupSessionMessenger(session: groupSession)

        self.groupSession.join()
        // …
    }
}
```

For more information about establishing a group session, see [`GroupSession`](/documentation/GroupActivities/GroupSession).

### Receive Messages from Other Devices

The system delivers messages to your app asynchronously when they arrive and
adds them to a message sequence. Use the [`messages(of:)`](/documentation/GroupActivities/GroupSessionMessenger/messages(of:)-626qo) or
[`messages(of:)`](/documentation/GroupActivities/GroupSessionMessenger/messages(of:)-jvoz) method to retrieve the sequence you want and iterate
over its results. Use a `for`-`in` loop with the `await` keyword to iterate
asynchronously over the results. The following example shows how a Tic Tac Toe
game might retrieve moves sent by the current opponent. After receiving each
move, the code adds that move to the current participant’s board.

```
let sessionMessenger = GroupSessionMessenger(session: groupSession)

async {
    for await move in sessionMessenger.messages(of: TicTacToe.Move.self) {
        self.board.addMove(move)
    }
}
```

## Topics

### Creating a group session messenger

[`init(session:)`](/documentation/GroupActivities/GroupSessionMessenger/init(session:))

Creates a new group session messenger with
[`GroupSessionMessenger.DeliveryMode.reliable`](/documentation/GroupActivities/GroupSessionMessenger/DeliveryMode-swift.enum/reliable)
delivery mode and associates it with the specified session object.

### Sending data to the group

[`send(_:to:)`](/documentation/GroupActivities/GroupSessionMessenger/send(_:to:)-4o52m)

Sends a standard data object asynchronously to other participants in the group session.

[`send(_:to:)`](/documentation/GroupActivities/GroupSessionMessenger/send(_:to:)-2a4ku)

Sends a custom type asynchronously to other participants in the group session.

[`send(_:to:completion:)`](/documentation/GroupActivities/GroupSessionMessenger/send(_:to:completion:)-zufl)

Sends a standard data object to other participants in the group session.

[`send(_:to:completion:)`](/documentation/GroupActivities/GroupSessionMessenger/send(_:to:completion:)-9e0sn)

Sends a custom type to other participants in the group session.

[`Participants`](/documentation/GroupActivities/Participants)

The set of participants to include in messages.

### Receiving data from other participants

[`messages(of:)`](/documentation/GroupActivities/GroupSessionMessenger/messages(of:)-626qo)

Returns the asynchronous sequence of messages that contain a generic data object.

[`messages(of:)`](/documentation/GroupActivities/GroupSessionMessenger/messages(of:)-jvoz)

Returns the asynchronous sequence of messages that match the app-specific type.

[`GroupSessionMessenger.Messages`](/documentation/GroupActivities/GroupSessionMessenger/Messages)

An asynchronous sequence of messages sent to the session.

[`GroupSessionMessenger.MessageContext`](/documentation/GroupActivities/GroupSessionMessenger/MessageContext)

A structure that contains additional information about an incoming message, such as which device sent it.



---

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)