display-access

작성자: facebook

디스플레이 기능 설정, 디스플레이 가능 장치 선택, UI DSL, 아이콘, 버튼, 이미지 및 비디오 재생

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

Display Access (iOS)

Use MWDATDisplay to render content on Meta Ray-Ban Display glasses.

Use this skill with getting-started and permissions-registration when creating a full app. A Display app still needs Wearables.configure() at launch, Info.plist URL scheme configuration, URL callbacks through Wearables.shared.handleUrl(_:), and completed Meta AI registration before it can create a session.

Add the Display module

Add MWDATDisplay to the same app target that already uses MWDATCore. Import it next to core:

import MWDATCore
import MWDATDisplay

For a phone preview, add MWDATMockDevice alongside MWDATDisplay, enable MockDeviceKit, and pair a display-capable model:

import MWDATMockDevice

MockDeviceKit.shared.enable()
let mockDevice = try MockDeviceKit.shared.pairGlasses(model: .metaRayBanDisplay)
mockDevice.powerOn()
mockDevice.don()

// Render what the glasses would show, inside your app
let previewView = mockDevice.services.display.createPreviewView()

MockDisplayKit also exposes sendClick(identifier:) so tests can simulate taps.

Use the normal DeviceSession.addDisplay() API for both physical and mock devices. Wait until deviceForIdentifier(_:) reports linkState == .connected and compatibility() == .compatible before creating the session.

Display-specific app configuration

Use the getting-started Info.plist setup, then mirror the DisplayAccess sample for Display sessions:

  • Keep the CFBundleURLTypes URL scheme and route callbacks to Wearables.shared.handleUrl(_:).
  • Under MWDAT, set AppLinkURLScheme, MetaAppID, ClientToken, and TeamID. An empty, 0, or unexpanded $(META_APP_ID) value keeps the SDK in Developer Mode; production apps should use Wearables Developer Center values for MetaAppID and ClientToken, plus the Apple Developer Team ID.
  • Set UIBackgroundModes to processing, bluetooth-central, bluetooth-peripheral, and external-accessory; add UISupportedExternalAccessoryProtocols with com.meta.ar.wearable; and add NSBluetoothAlwaysUsageDescription. The DisplayAccess sample declares the first three background modes; keep the external-accessory mode and the accessory protocol so the Bluetooth Classic link stays available.
  • For high-bandwidth Display/video, include a non-empty NSLocalNetworkUsageDescription and NSBonjourServices with _bonjour._tcp. Display acquires link leases: core device discovery/session setup uses medium then low links, while Display uses medium then high links when available.

Select a display-capable device

Use the public display filter when creating an automatic selector:

let wearables = Wearables.shared
let deviceSelector = AutoDeviceSelector(
  wearables: wearables,
  filter: { device in device.supportsDisplay() }
)

Use SpecificDeviceSelector(device: selectedDevice.identifier) instead when your UI lets the user pick a specific Device. The initializer takes a DeviceIdentifier, not the whole Device.

AutoDeviceSelector updates from devicesStream(). Create it before the user taps the Display action, or wait for activeDeviceStream() to yield a non-nil device before calling createSession(deviceSelector:); otherwise createSession can throw DeviceSessionError.noEligibleDevice.

For a picker or Settings screen, list devices from Wearables.shared.devicesStream(), then look up metadata from deviceForIdentifier(_:). The DisplayAccess sample shows nameOrId(), deviceType().rawValue, linkState, and compatibility() and keeps addLinkStateListener / addCompatibilityListener tokens alive while rows are visible. If compatibility() == .deviceUpdateRequired, surface a firmware update action through Wearables.shared.openFirmwareUpdate().

Attach Display after the session starts

Create and start the DeviceSession, wait for .started, then add and start Display. Keep the state listener token alive for as long as you need updates, and observe session.errorStream() for async session failures.

import MWDATCore
import MWDATDisplay

@MainActor
final class DisplayController {
  private var deviceSession: DeviceSession?
  private var display: Display?
  private var displayStateToken: AnyListenerToken?
  private var sessionErrorTask: Task<Void, Never>?

  func connect() async {
    do {
      let wearables = Wearables.shared
      let selector = AutoDeviceSelector(
        wearables: wearables,
        filter: { $0.supportsDisplay() }
      )

      let session = try wearables.createSession(deviceSelector: selector)
      deviceSession = session
      sessionErrorTask = Task { [weak self] in
        for await error in session.errorStream() {
          await self?.showError(error.localizedDescription)
        }
      }

      let sessionStarted = Task {
        for await state in session.stateStream() {
          if state == .started {
            return
          }
        }
      }
      do {
        try session.start()
        await sessionStarted.value
      } catch {
        sessionStarted.cancel()
        throw error
      }

      let capability = try session.addDisplay()
      display = capability
      displayStateToken = capability.statePublisher.listen { [weak self] state in
        Task { @MainActor in
          if state == .started {
            self?.showStatusCard()
          }
        }
      }

      capability.start()
    } catch DeviceSessionError.datAppOnTheGlassesUpdateRequired {
      showDATGlassesAppUpdate()
    } catch {
      showError(error.localizedDescription)
    }
  }

  func disconnect() async {
    display?.onPlaybackEvent = nil
    display?.stop()
    deviceSession?.stop()
    sessionErrorTask?.cancel()
    sessionErrorTask = nil
    displayStateToken = nil
    display = nil
    deviceSession = nil
  }
}

For user-triggered content, match the sample's pending-action pattern: if the user taps "Try it" before Display is connected, store the send as a pending async action, attach to Display, and run the action when DisplayState.started arrives. Reset the display session when registration changes to .available or .unavailable.

Send display UI

Build exactly one root DisplayableView per send(_:) call. Each send replaces the previous content on the glasses and replaces the active tap handlers. Use a root FlexBox for UI, or a root VideoPlayer for video. Do not send Text, Button, Image, or Icon as the root; place them inside a FlexBox.

If a file also imports SwiftUI, Display DSL names such as Text, Button, and Image can be ambiguous. Prefer keeping Display builders in files that import MWDATDisplay without SwiftUI, or qualify the symbols as MWDATDisplay.Text, MWDATDisplay.Button, and MWDATDisplay.Image.

func showStatusCard() {
  Task {
    do {
      try await display?.send(
        FlexBox(direction: .column, spacing: 12) {
          Text("Bike ride", style: .heading)
          Text("Turn right in 200 ft", style: .body, color: .secondary)
          Button(
            label: "Done",
            style: .primary,
            iconName: .checkmark,
            onClick: { print("Done tapped") }
          )
        }
        .padding(24)
        .background(.card)
        .onTap { print("Card tapped") }
      )
    } catch {
      showError((error as? DisplayError)?.description ?? error.localizedDescription)
    }
  }
}

Group buttons and control layout

Wrap multiple buttons in a ButtonGroup rather than adding them directly to a FlexBox. Mark the default action with .actionRole(.primary). FlexBox, Text, Button, ButtonGroup, Image, and Icon all support .flexGrow(_:), .flexShrink(_:), and .alignSelf(_:); FlexBox also supports .padding(_:), .background(_:), and .onTap(_:).

FlexBox(direction: .row, spacing: 8, alignment: .center, crossAlignment: .center) {
  ButtonGroup {
    Button(label: "Previous", style: .primary, iconName: .triangleLeftVerticalLine, onClick: onPrevious)
    Button(label: "Next", style: .primary, iconName: .triangleRightVerticalLine, onClick: onNext)
      .actionRole(.primary)
    Button(label: "Watch video", style: .secondary, iconName: .videoCamera, onClick: onWatchVideo)
  }
}

FlexBox also accepts wrap: true and padding: EdgeInsets(...) in its initializer, and its @ComponentBuilder content supports for loops and if conditions.

Use images and built-in icons

Use HTTPS image URLs for remote images, or Image(image:) for a bundled UIImage. Use the IconName enum for built-in icons; do not invent raw icon strings. ButtonStyle is .primary, .secondary, or .outline; IconStyle is .filled or .outline.

try await display.send(
  FlexBox(direction: .row, spacing: 8, crossAlignment: .center) {
    Image(
      uri: "https://example.com/thumbnail.png",
      sizePreset: .fill,
      cornerRadius: .medium
    )
    Image(image: UIImage(resource: .oil), sizePreset: .fill, cornerRadius: .medium)
    Icon(name: .gear, style: .filled)
    Text("Device settings", style: .body)
  }
  .padding(24)
)

Send video

For URL-based video, send a root VideoPlayer. Use VideoPlayer(onError:) for video-specific errors, and use display.onPlaybackEvent for playback events. Set onPlaybackEvent before sending the video, clear it after terminal events if the flow is complete, and call sendVideoStop() if the user exits playback early. Blank or non-HTTP(S) URLs throw DisplayError.invalidVideoURL.

display.onPlaybackEvent = { event in
  if event.type == .ended || event.type == .stopped {
    Task { @MainActor in
      display.onPlaybackEvent = nil
      showStatusCard()
    }
  }
}

try await display.send(
  VideoPlayer(
    provider: .uri("https://example.com/tutorial.mp4"),
    codec: .mp4,
    onError: { error in
      Task { @MainActor in
        showError(error.localizedDescription)
      }
    }
  )
)

Display rules

  • Call Wearables.configure() at app launch and complete registration before creating the session.
  • Include the DisplayAccess sample's link-lease Info.plist keys when building a full Display app.
  • Wait for the DeviceSession to reach .started before calling addDisplay().
  • Handle DeviceSessionError.datAppOnTheGlassesUpdateRequired separately and offer Wearables.shared.openDATGlassesAppUpdate().
  • Call display.start(), then wait for DisplayState.started through statePublisher before sending user-triggered content.
  • Observe session.errorStream() so async session failures are surfaced.
  • Keep listener tokens alive; dropping a token stops that listener.
  • Use the getting-started setup for Info.plist URL schemes and route app-open URLs to Wearables.shared.handleUrl(_:).
  • Use nameOrId(), deviceType(), linkState, and compatibility() for device rows; keep link/compatibility listener tokens until the row is gone.
  • Use FlexBox.onTap and Button(label:onClick:) for interactions. The callbacks belong to the most recent sent view.
  • Use only public Display DSL names: FlexBox, Text, Button, ButtonGroup, Image, Icon, VideoPlayer, IconName, IconStyle, TextStyle, TextColor, ButtonStyle, ButtonGroupAlignment, ActionRole, ImageSize, CornerRadius, Direction, Alignment, Background, Edge, and EdgeInsets.
  • Call display.clearDisplay() when you want to remove content without stopping Display.
  • Clear display.onPlaybackEvent when the video flow is finished if you no longer need playback callbacks.
  • Stop Display before stopping the parent DeviceSession when the display experience ends.

Sample app

Use the Display Access sample app for a complete flow: registration, device selection, display attachment, interactive content, and video.

Links

facebook의 다른 스킬

gc-safe-coding
facebook
전체 설명과 근거는 doc/GCSafeCoding.md를 참조하십시오.
app-review-prep
facebook
Meta 앱을 App Review용으로 준비합니다 — 현재 상태, 미해결 요구 사항, 부여된 권한, 제출 내역을 확인합니다. 앱을 제출하기 전에 사용하세요…
api-health
facebook
Meta 앱의 API 상태를 모니터링합니다 — 비율 제한, 호출량, API 지원 중단 여부를 확인합니다. 트래픽 제한을 진단하거나, 용량을 계획하거나, API 버전 변경에 대비하는 데 사용합니다…
debug-webhooks
facebook
Meta 앱의 웹훅 문제를 해결합니다 — 활성 구독을 검사하고, 잘못된 구성을 식별하며, 테스트 페이로드를 전송하여 전달을 확인합니다. 다음과 같은 경우에 사용하세요…
api-integration
facebook
개발자가 Meta API 통합을 처음부터 설정하도록 안내합니다 — 적절한 API를 찾아내고, 설정 가이드, 인증 요구 사항 등을 가져옵니다…
webhook-setup
facebook
Meta 앱용 웹훅을 처음부터 끝까지 설정하세요 — 사용 가능한 주제를 탐색하고, 필드를 구독하고, 테스트 페이로드로 검증합니다. 웹훅을 구성할 때 사용하세요…
test-ui
facebook
iwsdk CLI를 사용하여 포크 예제에 대해 Test UI 시스템(PanelUI, ScreenSpace)을 테스트합니다.
flags
facebook
React 릴리스 채널 간 기능 플래그 상태를 검사하고 비교합니다. 모든 채널(www, www-modern, canary, next, experimental, rn 변형)의 플래그를 보거나 --diff로 특정 채널을 비교합니다. 출력 형식은 기본 테이블 보기, CSV 내보내기, 정리 상태 그룹화를 포함합니다. 플래그 상태는 기호로 표시됩니다: 활성화(✅), 비활성화(❌), 변형 테스트(🧪), 프로파일링 전용(📊). 일반적인 실수: __VARIANT__ 플래그는 www에서 두 상태 모두 테스트되며, --diff를 사용하여 의미 있는 차이를 찾습니다...