Contents

DocumentPreviewSession

Document session allows you to present the contents of a URL or Data.

Declaration

final class DocumentPreviewSession

Mentioned in

Overview

To start a DocumentPreviewSession preview, obtain an SpatialPreviewEndpoint through one of two paths:

When you have the endpoint, create a DocumentPreviewSession, the concrete session class that conforms to SpatialPreviewSession and Sendable. Initialize the session with a display name and the UTType of the content, then call start(endpoint:) with the endpoint to open the connection:

let observer = ConnectedSpatialEndpointObserver()

// Wait for a device to become available.
let endpoint = try await observer.endpoint

// Create and start the session.
let session = DocumentPreviewSession(name: "My Spatial Content", contentType: .jpeg)

try await session.start(endpoint: endpoint)

// Push initial content, then update as the document changes.
let spatialContentURL = URL(filePath: "/path/to/spatialContent.jpeg")
try await session.updateContents(url: spatialContentURL)

After starting a session, use updateContents(data:) to push a Data value directly to the device; this is useful when your document content is already in memory. Use updateContents(url:) to stream content from a file URL, which avoids loading the entire file into memory at once. Call either method each time the document changes.

Track connection changes using SpatialPreviewSessionState. When you finish, call close() to end the session cleanly.

Topics

Initializers

Instance Properties

Instance Methods

See Also

Preview sessions