Use https://wearables.developer.meta.com/docs/develop/dat/lifecycle-events/, then use the Wearables MCP endpoint https://mcp.developer.meta.com/wearables to call search_dat_docs for current Device Access Toolkit session lifecycle guidance. Inspect my session code first, then add the smallest lifecycle fix for STARTED, PAUSED, and STOPPED states, including interruption handling and resource cleanup. Avoid assuming transition reasons, keep UI state explicit, and run the relevant local checks.
DeviceSessionState is device-driven and delivered asynchronously. On Android, observe the state using state. On iOS, use stateStream().| State | Meaning | App expectation |
|---|---|---|
STOPPED | Session is inactive and not reconnecting. | Free resources. Wait for user action. |
STARTED | Session is active and streaming data. | Perform live work. |
PAUSED | Session is temporarily suspended. | Hold work. Paths may resume. |
DeviceSessionState does not expose the reason for a transition.DeviceSessionState and react without assuming the cause of a change. Start observing before you call start() so you don’t miss the first state changes.val session = Wearables.createSession(AutoDeviceSelector()).getOrThrow()
scope.launch {
session.state.collect { state ->
when (state) {
DeviceSessionState.STARTED -> onStarted()
DeviceSessionState.PAUSED -> onPaused()
DeviceSessionState.STOPPED -> onStopped()
else -> {}
}
}
}
session.start()
let session = try wearables.createSession(deviceSelector: AutoDeviceSelector(wearables: wearables))
let stateStream = session.stateStream()
try session.start()
for await state in stateStream {
switch state {
case .started: onStarted()
case .paused: onPaused()
case .stopped: onStopped()
default: break
}
}
STARTED, confirm UI shows that the device session is live.PAUSED, keep the connection and wait for STARTED or STOPPED.STOPPED, release device resources and allow the user to restart.DeviceSessionState when:STOPPED, while some input interactions pause a session and later resume it.DeviceSessionState changes to PAUSED:STARTED.hingeState) also affects connectivity. For details, see Read battery, wear, and thermal state from glasses.Wearables.devicesMetadata[deviceId]?.collect { metadata ->
if (metadata.linkState == LinkState.CONNECTED) {
onDeviceAvailable()
} else {
onDeviceUnavailable()
}
}
guard let device = Wearables.shared.deviceForIdentifier(deviceId) else { return }
device.addLinkStateListener { linkState in
if linkState == .connected {
onDeviceAvailable()
} else {
onDeviceUnavailable()
}
}.store(in: tokenBag)
ListenerTokenBag that lives as long as you need updates, such as a tokenBag property on your view model.DeviceSessionState to STOPPED.session.state/stateStream and handle all DeviceSessionState values.STOPPED or loss of availability.