NSDKSession
Declaration
final class NSDKSessionSummary
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")
// Create a VPS2 session for localization
let vps2Session = session.createVps2Session()
// Send frame data during AR session
let status = session.sendFrame(frameData)
Lifecycle
Use one NSDKSession at a time. Creating a second one while another is still referenced is
a programming error: the session is still created, and NSDK reports the problem rather than
terminating the app, but the two compete for the camera and overwrite each other's
process-wide configuration, so neither behaves reliably. Release the existing session first.
The session releases its native resources when its last reference goes away. Teardown is
synchronous, so once the previous session has been released a new one can be created
immediately — there is no window in which the old session is still being torn down.
Constructors
Constructor
Summary
Returns
A new NSDK session, or nil if configuration is invalid
Example
let config = Configuration()
// Configure settings...
if let session = NSDKSession(withConfig: config) {
// Session created successfully
}
Overload 1
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.
Returns
A new NSDK session, or nil if configuration loading fails
Example
if let session = NSDKSession(withJson: "/path/to/config.json") {
// Session created successfully
} else {
// Failed to load configuration
}
Overload 2
Summary
Convenience initializer that accepts an access token.
The token is sanitized and passed to native AuthManagerApi immediately via creation call.
Properties
| Name | Type | Summary |
|---|---|---|
| var currentFrame | NSDKFrameData | The most recently received NSDK frame, or nil before the first frame is available. |
| weak var dataSource | ( NSDKSessionDataSource)? | The component supplying the session with sensory data. NSDK does not retain the data source. Keep your own reference to it, or it is released and no frames are sent. |
| var isAuthorized | Bool | 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. |
| let nativeHandle | NSDKHandle | 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
| Name | Type | Summary |
|---|---|---|
| @MainActor acquireDepthSession | NSDKDepthSession | Returns the shared depth session, creating it on first call. Subsequent calls return the same instance. The session is inactive until start() iscalled. NSDKSession.update() will call update() on it automatically each frame onceit is started. |
| @MainActor acquireDeviceMappingSession | NSDKDeviceMappingSession | Returns the shared device mapping session, creating it on first call. Subsequent calls return the same instance. The session is inactive until start() iscalled. NSDKSession.update() will call update() on it automatically each frame onceit is started. The session holds a reference to the shared NSDKMapStorage, which is alsocreated on first call and reused on subsequent calls. |
| @MainActor acquireMapStorage | NSDKMapStorage | - |
| @MainActor acquireMeshDownloader | NSDKMeshDownloader | Creates a new Mesh Downloader instance. |
| @MainActor acquireMeshingSession | NSDKMeshingSession | Returns the shared meshing session, creating it on first call. Subsequent calls return the same instance. The session is inactive until start() iscalled. NSDKSession.update() will call update() on it automatically each frame onceit is started. |
| @MainActor acquireRecordingExporter | NSDKRecordingExporter | 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. |
| @MainActor acquireScanningSession | NSDKScanningSession | Returns the shared Scanning session, creating it on first call. Subsequent calls return the same instance. The session is inactive until start() iscalled. NSDKSession.update() will call update() on it automatically each frame onceit is started. |
| @MainActor acquireSceneSegmentationSession | NSDKSceneSegmentationSession | Returns the shared scene segmentation session, creating it on first call. Subsequent calls return the same instance. The session is inactive until start() iscalled. NSDKSession.update() will call update() on it automatically each frame onceit is started. |
| @MainActor acquireSitesSession | NSDKSitesSession | - |
| @MainActor acquireVps2Session | NSDKVps2Session | Returns the shared VPS2 session, creating it on first call. Subsequent calls return the same instance. The session is inactive until start() iscalled. NSDKSession.update() will call update() on it automatically each frame onceit is started. |
| createDashcamSession | NSDKDashcamSession | Creates a new dashcam session. |
| @MainActor destroy | void | 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. |
| @MainActor destroyAll | void | Destroys all feature sessions at once, releasing their native resources. This does not release the NSDKSession itself — the session stays usable and can createnew feature sessions afterwards. The session is released when its last reference goes away. |
| getAccessAuthInfo | AuthInfo? | Gets access token authentication information. Returns authentication information containing information about the current access token. |
| getRefreshAuthInfo | AuthInfo? | Gets refresh token authentication information. Returns authentication information containing information about the current refresh token. |
| static logout | void | 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 setAccessToken | void | Sets the access token on native (routed through AuthManagerApi via C-ABI). Empty or whitespace-only tokens are ignored by native. |
| setCallbackLogLevel | void | Sets the log level for callback logging. |
| setFileLogLevel | void | Sets the log level for file logging. |
| @MainActor setLogOutputPath | void | Sets the diagnostic output folder for log.txt, ardk_trace.log, and future VPS debugger files. |
| setStdoutLogLevel | void | Sets the log level for standard output logging. |
| update | void | Collects the latest requested sensor inputs from the assigned NsdkSessionDataSource and submits a single frame for processing.Call this once per camera frame. Because this is an expensive operation, consider throttling the calls if you notice degraded app performance. |
| static version | String | Retrieves the NSDK version string. |
Nested Types
Structs
| Name | Type | Summary |
|---|---|---|
| CloudEnvConfig | CloudEnvConfig | - |
| Configuration | Configuration | Configuration settings for initializing an NSDK session. This struct encapsulates various configuration options including device info, cloud environment settings, user credentials, and logging preferences. |
| DeviceInfo | DeviceInfo | - |
| UserConfig | UserConfig | - |
Creates a new NSDK session with a Configuration object.
Use this initializer for fine-grained control over NSDK configuration