shareplay-developer
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSharePlay Developer
SharePlay 开发者指南
Description and Goals
描述与目标
This skill provides comprehensive guidance for implementing SharePlay experiences with the GroupActivities framework. It covers activity definition, session lifecycle, state synchronization, UI surfaces, and visionOS spatial coordination.
本技能为使用GroupActivities框架实现SharePlay体验提供全面指导,涵盖活动定义、会话生命周期、状态同步、UI界面以及visionOS空间协同。
Goals
目标
- Enable developers to build SharePlay experiences across Apple platforms
- Guide proper GroupActivity definition and activation
- Support GroupSession lifecycle management
- Help implement state synchronization with messaging and journals
- Enable spatial coordination for visionOS immersive experiences (group immersive space)
- 帮助开发者在Apple平台上构建SharePlay体验
- 指导正确定义和激活GroupActivity
- 支持GroupSession生命周期管理
- 协助实现基于消息传递与日志的状态同步
- 为visionOS沉浸式体验(群组沉浸式空间)实现空间协同
What This Skill Should Do
本技能的适用场景
When implementing SharePlay features, this skill should:
- Guide activity setup - Help you define GroupActivity types and metadata
- Handle activation - Show how to check eligibility and activate SharePlay
- Manage sessions - Demonstrate GroupSession lifecycle and participant management
- Sync state - Provide patterns for messaging and journal-based synchronization
- Coordinate spatially - Show how to use SystemCoordinator for visionOS spatial experiences and group immersive spaces
- Present UI - Guide use of ShareLink and other SharePlay UI surfaces
Load the appropriate reference file from the tables below for detailed usage, code examples, and best practices.
在实现SharePlay功能时,本技能可:
- 指导活动设置 - 帮助你定义GroupActivity类型和元数据
- 处理激活流程 - 展示如何检查资格并激活SharePlay
- 管理会话 - 演示GroupSession生命周期和参与者管理
- 同步状态 - 提供基于消息传递和日志的同步模式
- 空间协同配置 - 展示如何使用SystemCoordinator实现visionOS空间体验和群组沉浸式空间
- UI界面呈现 - 指导使用ShareLink及其他SharePlay UI界面
如需详细用法、代码示例和最佳实践,请从下表加载对应的参考文件。
Quick Start Workflow
快速开始流程
- Add the Group Activities capability and entitlement in Xcode.
com.apple.developer.group-session - Define a type per experience and keep its data minimal and
GroupActivity.Codable - Provide with a clear title, type, and fallback URL.
GroupActivityMetadata - Check and activate or present SharePlay UI.
GroupStateObserver.isEligibleForGroupSession - Listen for sessions with and store the session strongly.
for await session in Activity.sessions() - Configure before
SystemCoordinatorwhen spatial personas or immersive spaces are involved.join() - Call only after UI and state are ready.
session.join() - Sync state with (small, time-sensitive) or
GroupSessionMessenger(attachments).GroupSessionJournal - Observe and send a state snapshot for late joiners.
activeParticipants - Call or
leave()and cancel tasks when the session invalidates.end()
- 在Xcode中添加Group Activities功能和权限。
com.apple.developer.group-session - 为每个体验定义一个类型,确保其数据精简且符合
GroupActivity协议。Codable - 提供包含清晰标题、类型和备用URL的。
GroupActivityMetadata - 检查,然后激活或呈现SharePlay UI。
GroupStateObserver.isEligibleForGroupSession - 通过监听会话,并保持对会话的强引用。
for await session in Activity.sessions() - 当涉及空间角色或沉浸式空间时,在调用前配置
join()。SystemCoordinator - 仅在UI和状态准备就绪后调用。
session.join() - 使用(小型、时间敏感数据)或
GroupSessionMessenger(附件)同步状态。GroupSessionJournal - 监听,并为晚加入的参与者发送状态快照。
activeParticipants - 当会话失效时,调用或
leave()并取消任务。end()
visionOS Launch-Only Workflow (Same Space, No Sync)
visionOS 仅启动流程(同一空间,无同步)
Use this when you only want participants to enter the same immersive space with spatial coordination, without synchronizing entities or interactions yet.
- Define a with lightweight metadata and
GroupActivity.GroupActivityTransferRepresentation - Provide a that observes sessions and configures
SharePlayManager:SystemCoordinatorsupportsGroupImmersiveSpace = true- (or another appropriate template)
spatialTemplatePreference = .sideBySide
- In your scene, set
ImmersiveSpaceso the system can colocate participants..immersiveEnvironmentBehavior(.coexist) - Provide a start button:
- If FaceTime is active and activation is preferred, call .
activate() - Otherwise present (UIKit) or
GroupActivitySharingController(SwiftUI).ShareLink
- If FaceTime is active and activation is preferred, call
- Join the session with once configured.
session.join()
当你仅希望参与者进入同一沉浸式空间并实现空间协同,但暂不同步实体或交互时,可使用此流程。
- 定义一个包含轻量级元数据和的
GroupActivityTransferRepresentation。GroupActivity - 提供一个来监听会话并配置
SharePlayManager:SystemCoordinator- 设置
supportsGroupImmersiveSpace = true - 设置(或其他合适的模板)
spatialTemplatePreference = .sideBySide
- 设置
- 在你的场景中,设置
ImmersiveSpace,以便系统可以定位参与者。.immersiveEnvironmentBehavior(.coexist) - 提供一个启动按钮:
- 如果FaceTime处于活跃状态且优先激活,调用。
activate() - 否则,在UIKit中使用,或在SwiftUI中使用
GroupActivitySharingController。ShareLink
- 如果FaceTime处于活跃状态且优先激活,调用
- 配置完成后,调用加入会话。
session.join()
Information About the Skill
技能相关信息
Core Concepts
核心概念
Activity Definition
活动定义
- Use to define the shareable experience and keep payloads minimal.
GroupActivity - Provide with title, subtitle, preview image, and fallback URL.
GroupActivity.metadata - Set to a matching
GroupActivityMetadata.typevalue.ActivityType - Use from
GroupActivityActivationResultto decide activation.prepareForActivation() - Use for
GroupActivityTransferRepresentationand share sheets.ShareLink
- 使用定义可共享的体验,并保持负载精简。
GroupActivity - 为提供标题、副标题、预览图和备用URL。
GroupActivity.metadata - 将设置为匹配的
GroupActivityMetadata.type值。ActivityType - 使用返回的
prepareForActivation()决定激活方式。GroupActivityActivationResult - 为和分享面板使用
ShareLink。GroupActivityTransferRepresentation
Session Lifecycle and Participants
会话生命周期与参与者
- Use to manage the live activity; call
GroupSession,join(), orleave().end() - Observe ,
GroupSession.state, andactiveParticipantsto drive UI.isLocallyInitiated - Use to map sessions to scenes when needed.
GroupSession.sceneSessionIdentifier - Call when the activity needs the app visible.
requestForegroundPresentation() - Use or
GroupSession.showNotice(_:)for system playback notices.postEvent(_:)
- 使用管理实时活动;调用
GroupSession、join()或leave()。end() - 监听、
GroupSession.state和activeParticipants以驱动UI。isLocallyInitiated - 必要时,使用将会话映射到场景。
GroupSession.sceneSessionIdentifier - 当活动需要应用可见时,调用。
requestForegroundPresentation() - 使用或
GroupSession.showNotice(_:)发送系统播放通知。postEvent(_:)
Messaging and Transfer
消息传递与传输
- Use for small messages (<= 256 KB).
GroupSessionMessenger - Use delivery for critical state and
.reliablefor high-frequency updates..unreliable - Use for attachments and large data (<= 100 MB).
GroupSessionJournal
- 使用传输小型消息(≤256 KB)。
GroupSessionMessenger - 对关键状态使用交付模式,对高频更新使用
.reliable交付模式。.unreliable - 使用传输附件和大型数据(≤100 MB)。
GroupSessionJournal
UI Surfaces to Start SharePlay
启动SharePlay的UI界面
- Use with
ShareLink+Transferablein SwiftUI.GroupActivityTransferRepresentation - Use in UIKit/AppKit when no FaceTime call is active.
GroupActivitySharingController - Use in share sheets when needed.
NSItemProvider.registerGroupActivity(...)
- 在SwiftUI中结合+
Transferable使用GroupActivityTransferRepresentation。ShareLink - 当FaceTime通话未激活时,在UIKit/AppKit中使用。
GroupActivitySharingController - 必要时,在分享面板中使用。
NSItemProvider.registerGroupActivity(...)
visionOS Spatial Coordination
visionOS空间协同
- Use from
SystemCoordinatorfor spatial layout.GroupSession.systemCoordinator - Set and
spatialTemplatePreferenceas needed.supportsGroupImmersiveSpace - Use and
localParticipantStatesto track poses.remoteParticipantStates - Use to choose the primary scene.
groupActivityAssociation(_:) - For immersive spaces, prefer on the
.immersiveEnvironmentBehavior(.coexist)scene to allow co-location.ImmersiveSpace
- 使用提供的
GroupSession.systemCoordinator进行空间布局。SystemCoordinator - 根据需要设置和
spatialTemplatePreference。supportsGroupImmersiveSpace - 使用和
localParticipantStates跟踪姿态。remoteParticipantStates - 使用选择主场景。
groupActivityAssociation(_:) - 对于沉浸式空间,建议在场景上设置
ImmersiveSpace以支持共定位。.immersiveEnvironmentBehavior(.coexist)
Reference Files
参考文件
| Reference | When to Use |
|---|---|
| When looking for GroupActivities-focused code samples and excerpts. |
| When implementing “launch-only” SharePlay for a visionOS immersive space (same space, no sync). |
| When wiring the start button (FaceTime-active activation vs share sheet fallback). |
| 参考文件 | 使用场景 |
|---|---|
| 查找GroupActivities相关代码示例和片段时使用。 |
| 为visionOS沉浸式空间实现“仅启动”SharePlay(同一空间,无同步)时使用。 |
| 配置启动按钮(FaceTime激活状态下的激活与分享面板回退)时使用。 |
Implementation Patterns
实现模式
- Send a full state snapshot when new participants join.
- Keep UI state separate from shared game state to reduce message churn.
- Use for transient actions and
GroupSessionMessengerfor durable data.GroupSessionJournal - Prefer AVFoundation coordinated playback for media sync.
- 当新参与者加入时发送完整状态快照。
- 将UI状态与共享游戏状态分离,以减少消息传输量。
- 使用传输临时操作,使用
GroupSessionMessenger传输持久化数据。GroupSessionJournal - 对于媒体同步,优先使用AVFoundation协同播放。
Pitfalls and Checks
常见陷阱与检查项
- Keep data minimal; send state changes via messenger or journal.
GroupActivity - Store strong references to ,
GroupSession, andGroupSessionMessenger.GroupSessionJournal - Join only when UI and state are ready; call on teardown.
leave() - Handle late joiners by sending the current state snapshot on change.
activeParticipants - For visionOS group immersive space: if participants don't colocate, verify , your scene's
supportsGroupImmersiveSpace, and that.immersiveEnvironmentBehavior(.coexist)is configured beforeSystemCoordinator.join()
- 保持数据精简;通过messenger或journal发送状态变更。
GroupActivity - 对、
GroupSession和GroupSessionMessenger保持强引用。GroupSessionJournal - 仅在UI和状态准备就绪后加入会话;在销毁时调用。
leave() - 当变化时,通过发送当前状态快照处理晚加入的参与者。
activeParticipants - 对于visionOS群组沉浸式空间:如果参与者无法共定位,请检查、场景的
supportsGroupImmersiveSpace设置,以及是否在.immersiveEnvironmentBehavior(.coexist)前配置了join()。SystemCoordinator