SharePlay visionOS Immersive Space + Window

I'd like to implement a fully immersive space that's experienced by multiple Vision Pro users simultaneously via SharePlay. To do this, the multiple Vision Pro users will join a SharePlay-enabled visionOS window that has a button to enter a fully immersive space, which is also SharePlay-enabled. I tried following the WWDC sessions and docs, but they don't provide enough detail about integrating SharePlay into an existing window and immersive space. How can I adjust my SharePlay code so it makes my visionOS window + fully immersive space SharePlay-able? Please see existing code below for a SharePlay visionOS widow, thank you. P.S. WWDC ref. https://developer.apple.com/videos/play/wwdc2023/10087

import SwiftUI
import RealityKit
import RealityKitContent
import GroupActivities
import LinkPresentation

struct SharePlayWorld: View, GroupActivity {
    @Environment(ViewModel.self) private var model
    @Environment(\.openWindow) private var openWindow
    @Environment(\.dismissWindow) private var dismissWindow
    
    @Environment(\.openImmersiveSpace) private var openImmersiveSpace
    @Environment(\.dismissImmersiveSpace) private var dismissImmersiveSpace
    
    var body: some View {
        @Bindable var model = model
        
        Toggle(
            model.isShowingPracticeSpace ? "Leave Space" : "Enter Space",
            isOn: $model.isShowingPracticeSpace
        )
        .onChange(of: model.isShowingPracticeSpace) { _, isShowing in
            Task {
                if isShowing
                {
                    await openImmersiveSpace(id: "SharePlayWorld")
                }
                else
                {
                    await dismissImmersiveSpace()
                }
            }
        }
        .toggleStyle(.button)
    }
    
    // SHAREPLAY CODE
    private func startSharePlaySession() async {
        
        
        for await session in SharePlayWorld.sessions() {
            guard let systemCoordinator = await session.systemCoordinator else { continue }

            let isLocalParticipantSpatial = systemCoordinator.localParticipantState.isSpatial

            Task.detached {
                for await localParticipantState in systemCoordinator.localParticipantStates {
                    if localParticipantState.isSpatial {
                        // Start syncing scroll position
                    } else {
                        // Stop syncing scroll position
                    }
                }
            }
            
            var configuration = SystemCoordinator.Configuration()
                configuration.spatialTemplatePreference = .sideBySide
                systemCoordinator.configuration = configuration

                session.join()
        }
        
        // Create the activity
        let activity = SharePlayWorld()

        // Register the activity on the item provider
        let itemProvider = NSItemProvider()
        itemProvider.registerGroupActivity(activity)

        // Create the activity items configuration
        let configuration = await UIActivityItemsConfiguration(itemProviders: [itemProvider])

        // Provide the metadata for the group activity
        configuration.metadataProvider = { key in
            guard key == .linkPresentationMetadata else { return nil }
            let metadata = LPLinkMetadata()
            metadata.title = "Explore Together"
            metadata.imageProvider = NSItemProvider(object: UIImage(named: "explore-activity")!)
            return metadata
        }
        self.activityItemsConfiguration = configuration
    }
}

#Preview {
    SharePlayWorld()
        .environment(ViewModel())
}
Answered by Vision Pro Engineer in 788970022

Indicate your app supports a shared context when an immersive space is open by setting supportsGroupImmersiveSpace to true.

Here's the code in context:

var configuration = SystemCoordinator.Configuration()

// make this change
configuration.supportsGroupImmersiveSpace = true

configuration.spatialTemplatePreference = .sideBySide
systemCoordinator.configuration = configuration

See the related documentation for more detail.

Hi there - thanks for the question! This is a broad question and seems like something we could best help with by diving into your code with you through a Technical Support Incident. Would you be willing to open one so that we can get this working together? Thank you!

Did you get this figured out J0hn? I didn’t think it was possible to use shareplay in a full immersive space

If anyone still needs help with this I can make a new post and explain my solution. Very confusing initially until you understand the almost non-existent documentation that was graciously provided to us.

Indicate your app supports a shared context when an immersive space is open by setting supportsGroupImmersiveSpace to true.

Here's the code in context:

var configuration = SystemCoordinator.Configuration()

// make this change
configuration.supportsGroupImmersiveSpace = true

configuration.spatialTemplatePreference = .sideBySide
systemCoordinator.configuration = configuration

See the related documentation for more detail.

Adding Spatial Persona support to an activity contains relevant information on this topic.

SharePlay visionOS Immersive Space + Window
 
 
Q