Skip to main content
API Reference NSDK

NSDKSession

The main entry point for the NSDK (Native SDK) framework....

Declaration

final class NSDKSession

Summary

The main entry point for the NSDK (Native SDK) framework. NSDKSession provides the core functionality for AR applications, managing the lifecycle of NSDK features and serving as a factory for specialized sessions like VPS2, scanning, and mapping. This class handles frame data processing, configuration management, and resource cleanup.

Overview

Use NSDKSession to:

  • Initialize the NSDK with auth tokens or a configuration file
  • Send camera frame data for processing
  • Create specialized feature sessions (VPS2, Scanning, Mapping)
  • Query required input data formats
  • Manage the lifecycle of NSDK resources

Example Usage

// Initialize with tokens
let session = NSDKSession(accessToken: "access-token", refreshToken: "refresh-token")
// Create a VPS2 session for localization
let vps2Session = session.createVps2Session()
// Send frame data during AR session
let status = session.sendFrame(frameData)

Constructors

Constructor

@MainActor convenience init?(withConfig config: Configuration)

Summary

Creates a new NSDK session with a Configuration object.
Use this initializer for fine-grained control over NSDK configuration
- Parameter config: The configuration object with defined settings
- Returns: A new NSDK session, or nil if configuration is invalid
## Example
swift <br />let config = Configuration() <br />// Configure settings... <br />if let session = NSDKSession(withConfig: config) &#123; <br /> // Session created successfully <br />&#125; <br />


Overload 1

@MainActor convenience init?(withJson configFilePath: String, logCallback: NSDKLogCallback? = nil)

Summary

Creates a new NSDK session from a JSON configuration file.
Use this initializer for fine-grained control over NSDK configuration
or when loading settings from a configuration file.
- Parameters:
- configFilePath: Path to the JSON configuration file
- logCallback: Optional callback to receive NSDK log messages
- Returns: A new NSDK session, or nil if configuration loading fails
## Example
swift <br />if let session = NSDKSession(withJson: "/path/to/config.json") &#123; <br /> // Session created successfully <br />&#125; else &#123; <br /> // Failed to load configuration <br />&#125; <br />


Overload 2

@MainActor convenience init(accessToken: String, useLidar: Bool = true, pathConfig: NSDKPathConfig? = nil, logCallback: NSDKLogCallback? = nil)

Summary

Convenience initializer that accepts an access token.
The token is sanitized and passed to native AuthManagerApi immediately via creation call.


Properties

NameTypeSummary
var currentFrameNSDKFrameData
-
weak var dataSource ( NSDKSessionDataSource)?
The component supplying the session with sensory data.
var isAuthorizedBool
Returns true if a valid, non-expired access token is available.
Use this to check if features requiring authentication can be used.
If a feature returns an auth error, poll this property until it returns true
before retrying.
## Example
// After receiving an auth error from a feature:
while !session.isAuthorized {
try await Task.sleep(nanoseconds: 1_000_000_000) // 1 second
}
// Retry the feature call
let nativeHandleNSDKHandle
The native handle to the underlying NSDK C API instance.
This handle is used internally to communicate with the native NSDK library
and should not be modified directly by application code.

Methods

NameTypeSummary
@MainActor acquireDepthSessionNSDKDepthSession
Returns the shared depth session, creating it on first call.
Subsequent calls return the same instance. The session is inactive until start() is
called. NSDKSession.update() will call update() on it automatically each frame once
it is started.
- Important: Must be called from the main thread.
@MainActor acquireDeviceMappingSessionNSDKDeviceMappingSession
Returns the shared device mapping session, creating it on first call.
Subsequent calls return the same instance. The session is inactive until start() is
called. NSDKSession.update() will call update() on it automatically each frame once
it is started.
The session holds a reference to the shared NSDKMapStorage, which is also
created on first call and reused on subsequent calls.
- Important: Must be called from the main thread.
@MainActor acquireMapStorageNSDKMapStorage
- Important: Must be called from the main thread.
@MainActor acquireMeshDownloaderNSDKMeshDownloader
Creates a new Mesh Downloader instance.
- Returns: A new NSDKMeshDownloader attached to this NSDK session.
- Important: Must be called from the main thread.
@MainActor acquireMeshingSessionNSDKMeshingSession
Returns the shared meshing session, creating it on first call.
Subsequent calls return the same instance. The session is inactive until start() is
called. NSDKSession.update() will call update() on it automatically each frame once
it is started.
- Important: Must be called from the main thread.
@MainActor acquireRecordingExporterNSDKRecordingExporter
Creates a new Recording Exporter session.
Recording Export enables the conversion and export of saved scan recordings
to various formats for external processing or sharing. This session manages
the export workflow from scan selection through format conversion and output.
- Returns: A new Recording Exporter session attached to this NSDK session
- Important: Must be called from the main thread.
@MainActor acquireScanningSessionNSDKScanningSession
Returns the shared Scanning session, creating it on first call.
Subsequent calls return the same instance. The session is inactive until start() is
called. NSDKSession.update() will call update() on it automatically each frame once
it is started.
- Important: Must be called from the main thread.
@MainActor acquireSceneSegmentationSessionNSDKSceneSegmentationSession
Returns the shared scene segmentation session, creating it on first call.
Subsequent calls return the same instance. The session is inactive until start() is
called. NSDKSession.update() will call update() on it automatically each frame once
it is started.
- Important: Must be called from the main thread.
@MainActor acquireSitesSessionNSDKSitesSession
-
@MainActor acquireVps2SessionNSDKVps2Session
Returns the shared VPS2 session, creating it on first call.
Subsequent calls return the same instance. The session is inactive until start() is
called. NSDKSession.update() will call update() on it automatically each frame once
it is started.
- Important: Must be called from the main thread.
@MainActor destroyvoid
Destroys a specific session, stopping it and releasing its native resources.
After this call the session is removed from disposables and must not be used again.
- Parameter session: The session to destroy. Must have been created by this NSDKSession.
- Important: Must be called from the main thread.
@MainActor destroyAllvoid
Destroys all sessions at once, releasing all native resources.
Use this on reset or when the NSDKSession is no longer needed.
- Important: Must be called from the main thread.
getAccessAuthInfoAuthInfo?
Gets access token authentication information.
Returns authentication information containing information about the current access token.
- Returns: AuthInfo containing access token claims, or nil if the operation fails
getRefreshAuthInfoAuthInfo?
Gets refresh token authentication information.
Returns authentication information containing information about the current refresh token.
- Returns: AuthInfo containing refresh token claims, or nil if the operation fails
static logoutvoid
Clears cached auth tokens from persistent storage without requiring an NSDK session.
This is the preferred logout path. It can be called before NSDK is initialized or after
it has been destroyed. Any running session will pick up the cleared tokens on its next
reconciliation cycle.
@MainActor setAccessTokenvoid
Sets the access token on native (routed through AuthManagerApi via C-ABI).
Empty or whitespace-only tokens are ignored by native.
- Important: Must be called from the main thread.
setCallbackLogLevelvoid
Sets the log level for callback logging.
- Parameter logLevel: The desired log level for callback logging
setFileLogLevelvoid
Sets the log level for file logging.
- Parameter logLevel: The desired log level for file logging
setStdoutLogLevelvoid
Sets the log level for standard output logging.
- Parameter logLevel: The desired log level for standard output
updatevoid
Collects the latest requested sensor inputs from the assigned
NsdkSessionDataSource and submits a single frame for processing.
static versionString
Retrieves the NSDK version string.

Nested Types

Structs

NameTypeSummary
CloudEnvConfigCloudEnvConfig
-
ConfigurationConfiguration
Configuration settings for initializing an NSDK session.
This struct encapsulates various configuration options
including device info, cloud environment settings, user credentials,
and logging preferences.
DeviceInfoDeviceInfo
-
UserConfigUserConfig
-