GroupActivities / SharePlay
Build shared real-time experiences using the GroupActivities framework. SharePlay connects people over FaceTime, Messages, AirDrop, and nearby visionOS sharing, synchronizing media playback, app state, or custom data.
Contents
- Setup
- Defining a GroupActivity
- Session Lifecycle
- Sending and Receiving Messages
- Coordinated Media Playback
- Starting SharePlay from Your App
- GroupSessionJournal: File Transfer
- Common Mistakes
- Review Checklist
- References
Setup
Capability
Add the Group Activities capability to the app target in Xcode. Xcode adds the required entitlement and updates the provisioning profile:
Configure this only for app targets. Group Activities are not available in widgets, extensions, or App Clips.
Checking Eligibility
Observe changes reactively:
Defining a GroupActivity
Conform to GroupActivity and provide metadata:
Activity Types
GroupActivity is Codable; stored activity data must be codable. Add
Transferable only for SwiftUI ShareLink, SharePlay over AirDrop, or
AppKit/UIKit share sheets. Keep payloads minimal: use identifiers or URLs
instead of large data.
Session Lifecycle
Listening for Sessions
Set up a long-lived task to receive sessions when another participant starts the activity:
Session States
Handling State Changes
Leaving and Ending
Sending and Receiving Messages
Use GroupSessionMessenger to sync small, time-sensitive app state between
participants.
Defining Messages
Messages must be Codable; keep each message under 256 KB.
Sending
Receiving
Delivery Modes
Use .reliable for state-changing actions such as selections or turns. Use
.unreliable for high-frequency ephemeral data such as cursor positions,
drawing strokes, and reactions.
Coordinated Media Playback
For video/audio, use AVPlaybackCoordinator with AVPlayer:
Once connected, AVFoundation synchronizes play/pause, seeking, rate, playback speed, and time. Do not put AVPlayer transport fields in messenger messages or snapshots, including late-joiner snapshots; use custom messages only for state outside playback.
Starting SharePlay from Your App
Using GroupActivitySharingController (UIKit)
When no conversation is active (i.e., isEligibleForGroupSession is false),
use GroupActivitySharingController to let the user pick contacts first:
Use the shareplay SF Symbol for custom controls. Treat GroupActivityMetadata
as discovery copy: concise title, subtitle, image, and type aligned with the
entry point. Keep sibling domains out: GameKit owns auth, matchmaking,
leaderboards, achievements, and voice/chat; TabletopKit owns seats, board
equipment, spatial placement, turns, rules, and authoritative tabletop state;
AVKit owns playback UI. SharePlay owns invitations, lifecycle, participants, and
coordination handoffs. See references/shareplay-patterns.md [blocked] for SwiftUI ShareLink, AirDrop, and direct activation patterns.
GroupSessionJournal: File Transfer
For larger, non-time-sensitive attachments, use GroupSessionJournal instead
of GroupSessionMessenger. Journal items must conform to Transferable, are
available to late joiners, and are limited to 100 MB. It requires iOS/iPadOS/tvOS
17+, macOS 14+, or visionOS 1+. For larger/protected assets, share a pointer or manifest and use server storage or app-managed file transfer.
Common Mistakes
DON'T: Forget to call session.join()
Configure the stored session, messenger, and observers, then call join(). The
canonical long-lived manager in Session Lifecycle shows the required order.
DON'T: Forget to leave or end sessions
DON'T: Assume all participants have the same state
DON'T: Use SharePlay transports for large/protected assets
DON'T: Send redundant messages for media playback
DON'T: Observe sessions in a view that gets recreated
Own the sessions() listener in a long-lived manager, not a recreatable view.
Use the manager lifecycle shown above and cancel its child tasks on invalidation.
Review Checklist
- Group Activities capability added to the app target only
-
GroupActivitystruct isCodablewith meaningful metadata -
Transferableconformance added when usingShareLink, AirDrop, or share sheets -
sessions()observed in a long-lived object (not a SwiftUI view body) -
session.join()called after receiving and configuring the session -
session.leave()called when the user navigates away or dismisses -
GroupSessionMessengermessages stay under 256 KB with appropriatedeliveryMode - Late-joining participants receive current state on connection
-
$stateand$activeParticipantspublishers observed for lifecycle changes -
GroupSessionJournalused for non-time-sensitiveTransferableattachments -
AVPlaybackCoordinatorused for media sync (not manual messages) -
GroupStateObserver.isEligibleForGroupSessionchecked before showing SharePlay UI -
GroupActivitySharingControllerused when no conversation is active - Session invalidation handled with cleanup of messenger, journal, and tasks
References
- Extended patterns (SwiftUI sharing, collaborative canvas, spatial Personas): references/shareplay-patterns.md [blocked]
- Configuring Group Activities
- GroupActivities framework
- GroupActivity protocol
- GroupSession
- GroupSessionMessenger
- GroupSessionJournal
- GroupStateObserver
- GroupActivitySharingController
- Defining your app's SharePlay activities
- Presenting SharePlay activities from your app's UI
- Synchronizing data during a SharePlay activity
- Supporting coordinated media playback
- SharePlay HIG


