<< All versions
Skill v1.0.1
currentAutomated scan100/100facebook/meta-wearables-dat-ios/sample-app-guide
+2 new
──Details
PublishedOctober 25, 2026 at 07:35 AM
Content Hashsha256:0f08e028c38d9a2e...
Git SHAbbae597cd1c7
Bump Typepatch
──Files
Files (1 file, 7.5 KB)
SKILL.md7.5 KBactive
SKILL.md · 240 lines · 7.5 KB
version: "1.0.1" name: sample-app-guide description: Building a complete DAT app with camera streaming and photo capture
Sample App Guide (iOS)
Build an iOS DAT app with camera streaming and photo capture.
This walkthrough covers app setup, registration, streaming, and capture. Pair it with the CameraAccess sample.
Project setup
- Create a new Xcode project (SwiftUI App)
- Add the SDK via SPM:
https://github.com/facebook/meta-wearables-dat-ios - Add
MWDATCore,MWDATCamera, andMWDATMockDeviceto your target - Configure
Info.plist(see Getting Started)
App architecture
A typical DAT app has these components:
text
MyDATApp/├── MyDATApp.swift # App entry point, SDK init├── ViewModels/│ ├── WearablesViewModel.swift # Registration, device management│ └── StreamViewModel.swift # Streaming, photo capture└── Views/├── MainAppView.swift # Navigation├── RegistrationView.swift # Registration UI└── StreamView.swift # Video preview, capture button
SDK initialization
swift
import MWDATCore@mainstruct MyDATApp: App {init() {do {try Wearables.configure()} catch {assertionFailure("Wearables SDK configuration failed: \(error)")}}var body: some Scene {WindowGroup {MainAppView().onOpenURL { url inguardlet components = URLComponents(url: url, resolvingAgainstBaseURL: false),components.queryItems?.contains(where: { $0.name == "metaWearablesAction" }) == trueelse {return}Task {_ = try? await Wearables.shared.handleUrl(url)}}}}}
Wearables ViewModel
devicesStream() yields [DeviceIdentifier] (a [String]), not device objects. Resolve each identifier with wearables.deviceForIdentifier(_:) when you need nameOrId(), deviceType(), linkState, or compatibility().
swift
import MWDATCore@MainActorclass WearablesViewModel: ObservableObject {@Published var registrationState: RegistrationState@Published var devices: [DeviceIdentifier] = []private let wearables = Wearables.sharedinit() {registrationState = Wearables.shared.registrationState}func observeState() {Task {for await state in wearables.registrationStateStream() {self.registrationState = state}}Task {for await deviceIds in wearables.devicesStream() {self.devices = deviceIds}}}func register() async {try? await wearables.startRegistration()}func unregister() async {try? await wearables.startUnregistration()}}
Stream ViewModel
swift
import MWDATCameraimport MWDATCore@MainActorclass StreamViewModel: ObservableObject {@Published var currentFrame: UIImage?@Published var streamState: String = "Stopped"@Published var capturedPhoto: Data?private let wearables = Wearables.sharedprivate var deviceSession: DeviceSession?private var camera: Camera?private var stream: Stream?func startStream() async {let config = StreamConfiguration(videoCodec: .raw,resolution: .medium,frameRate: 24)let selector = AutoDeviceSelector(wearables: wearables)do {let deviceSession = try wearables.createSession(deviceSelector: selector)try deviceSession.start()// Wait for the device session to reach the started statefor await state in deviceSession.stateStream() {if state == .started { break }}guard let camera = try deviceSession.addCamera(config: config) else { return }self.deviceSession = deviceSessionself.camera = cameraself.stream = camera.stream} catch {return}guard let stream else { return }_ = stream.statePublisher.listen { [weak self] state inTask { @MainActor inself?.streamState = "\(state)"}}_ = stream.videoFramePublisher.listen { [weak self] frame inguard let image = frame.makeUIImage() else { return }Task { @MainActor inself?.currentFrame = image}}_ = stream.photoDataPublisher.listen { [weak self] photoData inTask { @MainActor inself?.capturedPhoto = photoData.data}}stream.start()}func stopStream() {// Stopping the camera cascades to its stream childcamera?.stop()deviceSession?.stop()stream = nilcamera = nildeviceSession = nil}func capturePhoto() {stream?.capturePhoto(format: .jpeg)}}
Behaviors the CameraAccess sample also covers
- Two explicit steps. "Start Session" creates and starts the
DeviceSession; "Preview" adds theCameraand starts the stream. Stopping the preview leaves the session connected so the user can start it again without re-creating the session. - Bind the UI to the SDK's own states. Mirror
DeviceSessionStateandStreamStateinstead of maintaining a parallel state machine, and show a busy indicator whilestarting,waitingForDevice, orstopping. - Background handling. On
UIApplication.didEnterBackgroundNotification, end the session. Suppress the teardown errors that the SDK emits during that intentional stop so the user does not see a false failure on return. - Update prompts. Watch
device.compatibility()withdevice.addCompatibilityListener; on.deviceUpdateRequired, offerWearables.shared.openFirmwareUpdate(). When session start reportsDeviceSessionError.datAppOnTheGlassesUpdateRequired, offerWearables.shared.openDATGlassesAppUpdate(). - Single error surface. Present
error.localizedDescriptionfromsession.errorPublisherandstream.errorPublisherin one alert rather than an app-maintained error map.
Testing with MockDeviceKit
Add mock device support to develop without glasses:
swift
import MWDATMockDevicefunc setupMockDevice() async {let mockDeviceKit = MockDeviceKit.sharedmockDeviceKit.enable()guard let device = try? mockDeviceKit.pairGlasses(model: .rayBanMeta) else { return }device.powerOn()device.unfold()device.don()if let videoURL = Bundle.main.url(forResource: "test_video", withExtension: "mp4") {let camera = device.services.cameracamera.setCameraFeed(fileURL: videoURL)}}func tearDownMockDevice() {MockDeviceKit.shared.disable()}
Allowed dependencies
Your DAT app should only depend on:
MWDATCore— always requiredMWDATCamera— for camera streamingMWDATMockDevice— for testing (can be test-only dependency)MWDATDisplay— for Display experiences