Contents

GroupActivityAssociationInteraction

An interaction configures a view’s association with the current SharePlay group activity.

Declaration

@MainActor @objc class GroupActivityAssociationInteraction

Overview

When a group of people join a SharePlay activity with their spatial Personas, the system selects a common, primary scene to arrange their spatial Personas around. This association between the group activity and a scene in your app creates a shared space for the spatial Personas to interact in; enabling participants to gesture at the associated scene and understand each other. For more information about spatial Personas and SharePlay on visionOS, see Adding spatial Persona support to an activity.

By default, the system uses your scene’s activation conditions in concert with your activity’s SceneAssociationBehavior to select a primary scene to associate with the activity. You can specify a different scene or dynamically change the primary associated scene by adding this interaction to a view and specifying that view as the GroupActivityAssociationKind/primary group activity association.

To add the interaction to a view, use addInteraction(_:).

// Create and store the scene association interaction
private let groupActivityAssociationInteraction = GroupActivityAssociationInteraction(
    associationKind: .primary("content-view")
)

override func viewDidLoad() {
    super.viewDidLoad()

    // Add the interaction to the view
    view.addInteraction(groupActivityAssociationInteraction)
}

If there are multiple scenes that are simultaneously configured with the primary group activity association, the most recently associated scene will be used. For example, if your app defines two windows and both contain views with the primary association kind, the most recently opened one will be used as the primary scene. If that second window is subsequently closed, the original window will be used again.

You can dynamically disable the group activity association of a view by setting the optional associationKind property to nil. You can later re-associate it by setting the associationKind to .primary.

func removeGroupActivityAssociation() {
   groupActivityAssociationInteraction.associationKind = nil
}

Topics

Initializers

Instance Properties

See Also

Spatial activities