session-lifecycle

Estados de sesión del dispositivo, pausa/reanudación, monitoreo de disponibilidad

npx skills add https://github.com/facebook/meta-wearables-dat-ios --skill session-lifecycle

Session Lifecycle (iOS)

Guide for managing device session states in DAT SDK integrations.

Overview

The DAT SDK runs work inside sessions. Meta glasses expose two experience types:

  • Device sessions — sustained access to device sensors and outputs
  • Transactions — short, system-owned interactions (notifications, "Hey Meta")

Your app observes session state changes — the device decides when to transition.

Session states

StateMeaningApp action
idleSession created but not startedCall start() when ready
startingSession is connecting to the deviceShow connecting state
startedSession active and ready for capabilitiesAdd or resume work
pausedTemporarily suspended by the deviceHold work, may resume
stoppingSession is cleaning upWait for terminal state
stoppedSession inactive and terminalFree resources, create a new session to restart

Observing session state

let session = try Wearables.shared.createSession(deviceSelector: AutoDeviceSelector(wearables: Wearables.shared))
try session.start()

Task {
    for await state in session.stateStream() {
        switch state {
        case .started:
            // Confirm UI shows session is live
        case .paused:
            // Keep connection, wait for started or stopped
        case .stopped:
            // Release resources, allow user to restart
        default:
            break
        }
    }
}

Stream state transitions

A Stream is obtained from the Camera 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
    }
}

Common transitions

The device changes session state when:

  • User performs a system gesture that opens another experience
  • Another app starts a device session
  • User removes or folds the glasses (Bluetooth disconnects)
  • User removes the app from Meta AI companion app
  • Connectivity between companion app and glasses drops

Pause and resume

When a session is paused:

  • The device keeps the connection alive
  • Streams stop delivering data
  • The device may resume by returning to started

Your app should not attempt to restart while paused — wait for started or stopped.

Device availability

Monitor device availability to know when sessions can start:

Task {
    for await devices in Wearables.shared.devicesStream() {
        // Update list of available glasses
    }
}

Key behaviors:

  • Closing hinges disconnects Bluetooth → forces stopped
  • Opening hinges restores Bluetooth but does not restart sessions
  • Start a new session after the device becomes available again

Implementation checklist

  • Handle all relevant session states (started, paused, stopped)
  • Monitor device availability before starting work
  • Release resources only after stopped
  • Don't infer transition causes — rely only on observable state
  • Don't restart during paused — wait for system to resume or stop

Links

Más skills de facebook

binary-size-analysis
facebook
Analiza los cambios de tamaño binario por commit de la biblioteca compartida hermesvm en un rango de commits de git. Genera un informe en markdown con tamaños por commit y tablas resumen de aumentos y disminuciones significativos.
official
modify-jsi-features
facebook
Guía para agregar nueva funcionalidad JSI a la capa de Interfaz JavaScript (JSI). Úsala cuando el usuario solicite añadir, crear o implementar nuevos métodos o características en…
official
non-interactive-git-rebase
facebook
Úsese cuando se necesite reordenar, dividir, eliminar o modificar commits de git que no sean el commit superior, sin acceso a un editor interactivo. Cubre el rebase programático mediante…
official
click-target
facebook
Encontrar y hacer clic en un objeto objetivo en XR. Úsalo al probar interacciones de UI, hacer clic en botones o verificar que los elementos interactuables funcionen correctamente.
official
iwsdk-planner
facebook
Guía de planificación de proyectos y mejores prácticas de IWSDK. Úsala al planificar nuevas funciones de IWSDK, diseñar sistemas/componentes, revisar la arquitectura de código de IWSDK o cuando…
official
iwsdk-ui-panel
facebook
Desarrolla e itera paneles de UI de IWSDK de manera eficiente. Úsalo al trabajar con componentes de PanelUI, depurar el diseño de la interfaz o mejorar el diseño de la UI en aplicaciones de IWSDK.
official
test-all
facebook
Orquestrador de pruebas paralelas. Ejecuta los 9 conjuntos de pruebas de forma concurrente mediante subagentes de Task y la CLI de iwsdk. Gestiona la compilación, configuración de ejemplos, servidores de desarrollo, lanzamiento de agentes,…
official
test-audio
facebook
Prueba el sistema de audio (carga de AudioSource, estado de reproducción, detener, audio espacial) contra el ejemplo de audio usando la CLI de iwsdk.
official