/mwdat-ios:session-lifecyclefrom mwdat-ios
Guides iOS developers on managing DAT SDK device session states (idle, starting, started, paused, stopping, stopped) with Swift code for observing state transitions, handling errors, and driving start/pause/resume/stop.
Ships in mwdat-ios. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Guide for managing device session states in DAT SDK integrations.
The DAT SDK runs work inside sessions. Meta glasses expose two experience types:
Your app observes session state changes. Your app drives start(), pause(), resume(), and stop(); the device can also pause, resume, or stop the session on its own.
| State | Meaning | App action |
|---|---|---|
idle | Session created but not started | Call start() when ready |
starting | Session is connecting to the device | Show connecting state |
started | Session active and ready for capabilities | Add or resume work |
paused | Temporarily suspended by pause() or the device | Hold work; call resume() or wait for the device to resume |
stopping | Session is cleaning up | Wait for terminal state |
stopped | Session inactive and terminal | Free resources, create a new session to restart |
let session = try Wearables.shared.createSession(deviceSelector: AutoDeviceSelector(wearables: Wearables.shared))
let states = session.stateStream()
try session.start()
Task {
for await state in states {
switch state {
case .started:
// Confirm UI shows session is live
break
case .paused:
// Hold work; call session.resume() or wait for started or stopped
break
case .stopped:
// Release resources, allow user to restart
break
default:
break
}
}
}
DeviceSession exposes both shapes: stateStream() / errorStream() as
AsyncStream, and statePublisher / errorPublisher as listener-token
Announcers. Pick one per call site; subscribe before calling start() so no
initial transition is missed.
errorStream() and errorPublisher emit DeviceSessionError. Handle
.noEligibleDevice (no matching device yet), .sessionAlreadyExists,
.capabilityAlreadyActive, the thermal/battery cases (.thermalCritical,
.thermalEmergency, .peakPowerShutdown, .batteryCritical), and
.datAppOnTheGlassesUpdateRequired, which is delivered as a one-shot event and
should open Wearables.shared.openDATGlassesAppUpdate().
start() uses typed throws, so you can catch the specific case:
do throws(DeviceSessionError) {
try session.start()
} catch .datAppOnTheGlassesUpdateRequired {
showGlassesAppUpdatePrompt()
} catch {
showError(error.localizedDescription)
}
A Stream is a capability attached to a started DeviceSession:
stopped → waitingForDevice → starting → streaming → paused → stopped
guard let camera = try session.addCamera(config: StreamConfiguration()) else { return }
let stream = camera.stream
let token = stream.statePublisher.listen { state in
Task { @MainActor in
// React to state changes
}
}
The device changes session state when:
Call pause() on a started session and resume() on a paused one. Both are sync fire-and-forget and do not throw: observe stateStream() or statePublisher for the started → paused → started transitions. pause() outside started and resume() outside paused are no-ops. The state changes only when the device confirms, so wait for paused before calling resume() (and for started before calling pause() again); earlier calls are ignored. If the observed state doesn't match what your app wants, call pause() or resume() again once it settles.
Button("Pause") { session.pause() } // started → paused
Button("Resume") { session.resume() } // paused → started
The device can also pause and resume the session on its own (for example a single touchpad tap). When a session is paused:
started when your app calls resume() or the device resumes itYour app should not restart the session while paused — call resume() or wait for started or stopped.
Monitor device availability to know when sessions can start:
Task {
for await deviceIds in Wearables.shared.devicesStream() {
// deviceIds is [DeviceIdentifier]; resolve details with deviceForIdentifier(_:)
}
}
A DeviceSelector also reports availability directly. AutoDeviceSelector and
SpecificDeviceSelector both expose activeDevice and activeDeviceStream(),
which yields nil when no eligible device is available:
let selector = AutoDeviceSelector(wearables: Wearables.shared)
Task {
for await deviceId in selector.activeDeviceStream() {
hasActiveDevice = deviceId != nil
}
}
Key behaviors:
stoppedstarted, paused, stopped)stoppedpaused — call resume() or wait for the device to resume or stopWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
dat-sdk, device-session, ios-sdk, session-management, wearables
npx claudepluginhub meta/meta-wearables-dat-ios --plugin mwdat-ios18 skills in this plugin
/audio-streamingReceive synchronized PCM audio frames through a Camera stream on iOS/camera-captureCapture standalone high-quality photos from connected glasses on iOS/camera-streamingStream, video frames, photo capture, resolution/frame rate configuration/dat-conventionsSwift patterns, async/await, naming conventions, key types for DAT SDK iOS development/dat-docs-mcpUse the Wearables DAT MCP server for live DAT documentation search with `search_dat_docs`, Muse Code, Claude Code, Codex, Cursor, and MCP Inspector/debuggingCommon issues, Developer Mode, version compatibility, state machine diagnosisOther plugins' skills for the same job