| name | shareplay-developer |
| description | Build, integrate, and troubleshoot SharePlay GroupActivities features, including GroupActivity definitions, activation flows, GroupSession lifecycle, messaging and journals, ShareLink and SharePlay UI surfaces, and visionOS spatial coordination. Use when implementing or debugging SharePlay experiences across Apple platforms, especially visionOS. |
SharePlay Dev (GroupActivities)
Overview
Use this skill to implement and debug SharePlay experiences with the GroupActivities framework, from activity definition through session lifecycle, state sync, and visionOS spatial coordination.
Quick start workflow
- Add the Group Activities capability and
com.apple.developer.group-sessionentitlement in Xcode. - Define a
GroupActivitytype per experience and keep its data minimal andCodable. - Provide
GroupActivityMetadatawith a clear title, type, and fallback URL. - Check
GroupStateObserver.isEligibleForGroupSessionand activate or present SharePlay UI. - Listen for sessions with
for await session in Activity.sessions()and store the session strongly. - Configure
SystemCoordinatorbeforejoin()when spatial personas or immersive spaces are involved. - Call
session.join()only after UI and state are ready. - Sync state with
GroupSessionMessenger(small, time-sensitive) orGroupSessionJournal(attachments). - Observe
activeParticipantsand send a state snapshot for late joiners. - Call
leave()orend()and cancel tasks when the session invalidates.
Core concepts
Activity definition
- Use
GroupActivityto define the shareable experience and keep payloads minimal. - Provide
GroupActivity.metadatawith title, subtitle, preview image, and fallback URL. - Set
GroupActivityMetadata.typeto a matchingActivityTypevalue. - Use
GroupActivityActivationResultfromprepareForActivation()to decide activation. - Use
GroupActivityTransferRepresentationforShareLinkand share sheets.
Session lifecycle and participants
- Use
GroupSessionto manage the live activity; calljoin(),leave(), orend(). - Observe
GroupSession.state,activeParticipants, andisLocallyInitiatedto drive UI. - Use
GroupSession.sceneSessionIdentifierto map sessions to scenes when needed. - Call
requestForegroundPresentation()when the activity needs the app visible. - Use
GroupSession.showNotice(_:)orpostEvent(_:)for system playback notices.
Messaging and transfer
- Use
GroupSessionMessengerfor small messages (<= 256 KB). - Use
.reliabledelivery for critical state and.unreliablefor high-frequency updates. - Use
GroupSessionJournalfor attachments and large data (<= 100 MB).
UI surfaces to start SharePlay
- Use
ShareLinkwithTransferable+GroupActivityTransferRepresentationin SwiftUI. - Use
GroupActivitySharingControllerin UIKit/AppKit when no FaceTime call is active. - Use
NSItemProvider.registerGroupActivity(...)in share sheets when needed.
visionOS spatial coordination
- Use
SystemCoordinatorfromGroupSession.systemCoordinatorfor spatial layout. - Set
spatialTemplatePreferenceandsupportsGroupImmersiveSpaceas needed. - Use
localParticipantStatesandremoteParticipantStatesto track poses. - Use
groupActivityAssociation(_:)to choose the primary scene.
Implementation patterns
- Send a full state snapshot when new participants join.
- Keep UI state separate from shared game state to reduce message churn.
- Use
GroupSessionMessengerfor transient actions andGroupSessionJournalfor durable data. - Prefer AVFoundation coordinated playback for media sync.
Pitfalls and checks
- Keep
GroupActivitydata minimal; send state changes via messenger or journal. - Store strong references to
GroupSession,GroupSessionMessenger, andGroupSessionJournal. - Join only when UI and state are ready; call
leave()on teardown. - Handle late joiners by sending the current state snapshot on
activeParticipantschange.
References
- references/REFERENCE.md - GroupActivities-focused code samples and excerpts.