---
title: DocumentPreviewSession
framework: spatialpreview
role: symbol
role_heading: Class
path: spatialpreview/documentpreviewsession
---

# DocumentPreviewSession

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

## Declaration

```swift
final class DocumentPreviewSession
```

## Mentioned in

Bridging an application’s custom USD runtime to Spatial Preview

## Overview

Overview To start a DocumentPreviewSession preview, obtain an SpatialPreviewEndpoint through one of two paths: Use ConnectedSpatialEndpointObserver when the visionOS device is already connected using Mac Virtual Display. Observe its isEndpointAvailable property to know when a device is ready, then access its endpoint property to retrieve the endpoint. Use SpatialPreviewDevicePicker, a View that presents nearby companion devices and calls its closure with the chosen SpatialPreviewEndpoint, when you want to let someone select a device interactively. 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

- [init(name:contentType:)](spatialpreview/documentpreviewsession/init(name:contenttype:).md)

### Instance Properties

- [contentType](spatialpreview/documentpreviewsession/contenttype.md)
- [name](spatialpreview/documentpreviewsession/name.md)

### Instance Methods

- [start(endpoint:)](spatialpreview/documentpreviewsession/start(endpoint:).md)
- [updateContents(data:)](spatialpreview/documentpreviewsession/updatecontents(data:).md)
- [updateContents(url:)](spatialpreview/documentpreviewsession/updatecontents(url:).md)

## Relationships

### Conforms To

- [Copyable](swift/copyable.md)
- [Escapable](swift/escapable.md)
- [Observable](observation/observable.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)
- [SpatialPreviewSession](spatialpreview/spatialpreviewsession.md)

## See Also

### Preview sessions

- [SpatialPreviewSession](spatialpreview/spatialpreviewsession.md)
- [USDPreviewSession](spatialpreview/usdpreviewsession.md)
