/mwdat-ios:sample-app-guidefrom mwdat-ios
Guides building an iOS DAT app with camera streaming and photo capture using the Meta Wearables SDK, covering setup, registration, and streaming.
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.
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.
https://github.com/meta/meta-wearables-dat-iosMWDATCore, MWDATCamera, and MWDATMockDevice to your targetInfo.plist and add the Hotspot Configuration capability (see Getting Started)A typical DAT app has these components:
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
import MWDATCore
@main
struct MyDATApp: App {
init() {
do {
try Wearables.configure()
} catch {
assertionFailure("Wearables SDK configuration failed: \(error)")
}
}
var body: some Scene {
WindowGroup {
MainAppView()
.onOpenURL { url in
guard
let components = URLComponents(url: url, resolvingAgainstBaseURL: false),
components.queryItems?.contains(where: { $0.name == "metaWearablesAction" }) == true
else {
return
}
Task {
_ = try? await Wearables.shared.handleUrl(url)
}
}
}
}
}
devicesStream() yields [DeviceIdentifier] (a [String]), not device objects.
Resolve each identifier with wearables.deviceForIdentifier(_:) when you need
nameOrId(), deviceType(), linkState, or compatibility().
import MWDATCore
@MainActor
class WearablesViewModel: ObservableObject {
@Published var registrationState: RegistrationState
@Published var devices: [DeviceIdentifier] = []
private let wearables = Wearables.shared
init() {
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()
}
}
import Combine
import MWDATCamera
import MWDATCore
import UIKit
@MainActor
class StreamViewModel: ObservableObject {
@Published var currentFrame: UIImage?
@Published var streamState: String = "Stopped"
@Published var capturedPhoto: Data?
private let wearables = Wearables.shared
private var deviceSession: DeviceSession?
private var camera: Camera?
private var stream: MWDATCamera.Stream?
private let streamTokens = ListenerTokenBag()
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)
let states = deviceSession.stateStream()
try deviceSession.start()
// Wait for the device session to reach the started state
for await state in states {
if state == .started { break }
}
guard let camera = try deviceSession.addCamera(config: config) else { return }
self.deviceSession = deviceSession
self.camera = camera
self.stream = camera.stream
} catch {
return
}
guard let stream else { return }
stream.statePublisher.listen { [weak self] state in
Task { @MainActor in
self?.streamState = "\(state)"
}
}.store(in: streamTokens)
stream.videoFramePublisher.listen { [weak self] frame in
guard let image = frame.makeUIImage() else { return }
Task { @MainActor in
self?.currentFrame = image
}
}.store(in: streamTokens)
stream.photoDataPublisher.listen { [weak self] photoData in
Task { @MainActor in
self?.capturedPhoto = photoData.data
}
}.store(in: streamTokens)
stream.start()
}
func stopStream() {
streamTokens.clear()
// Stopping the camera cascades to its stream child
camera?.stop()
deviceSession?.stop()
stream = nil
camera = nil
deviceSession = nil
// Cleared listeners won't see .stopped, so set the state here
streamState = "Stopped"
}
func capturePhoto() {
stream?.capturePhoto(format: .jpeg)
}
}
DeviceSession; "Preview" adds the Camera and starts the stream. Stopping the preview leaves the session connected so the user can start it again without re-creating the session.DeviceSessionState and StreamState instead of maintaining a parallel state machine, and show a busy indicator while starting, waitingForDevice, or stopping.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.device.compatibility() with device.addCompatibilityListener; on .deviceUpdateRequired, offer Wearables.shared.openFirmwareUpdate(). When session start reports DeviceSessionError.datAppOnTheGlassesUpdateRequired, offer Wearables.shared.openDATGlassesAppUpdate().error.localizedDescription from session.errorPublisher and stream.errorPublisher in one alert rather than an app-maintained error map.Add mock device support to develop without glasses:
import MWDATMockDevice
func setupMockDevice() async {
let mockDeviceKit = MockDeviceKit.shared
mockDeviceKit.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.camera
camera.setCameraFeed(fileURL: videoURL)
}
}
func tearDownMockDevice() {
MockDeviceKit.shared.disable()
}
Your DAT app should only depend on:
MWDATCore — always requiredMWDATCamera — for camera streamingMWDATMockDevice — for testing (can be test-only dependency)MWDATDisplay — for Display experiencesWhat SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub meta/meta-wearables-dat-ios --plugin mwdat-ios18 skills in this plugin
/dat-conventionsSwift patterns, async/await, naming conventions, key types for DAT SDK iOS developmentOther plugins' skills for the same job