Connection and Session
iOS: Connection and Session
Scenario
After authentication succeeds, use the singleton CxrClient.shared to establish the collaboration link with the glasses. Unlike Android, which explicitly constructs CXRLink, iOS typically distinguishes modes such as customView / customApp via initialization options and uses Combine event streams to observe audio, Custom View runtime state, etc.
Prerequisites
- “02-Authentication” has succeeded and
authis in an authorized state.
Recommended steps
- Configure client initialization options (mode, target package name, page name, etc.), following
RGCxrClientInitializationOptionsand the current SDK headers. - Hold
let client = CxrClient.sharedin your businessUIViewController(or inject a wrapper). - Subscribe to:
auth.statePublisher: continuously watch for logout/expiration.audioEventPublisher: audio link and data chunks.customViewRunningEventPublisher: whether the Custom View is running.
- Only after glasses-side scene building (the Custom View is running, or the Custom App has been launched according to SDK requirements) should you enable Audio, Photo, and Custom Command; do not enable them at “authenticated + link ready” alone.
Capability matrix (summary)
| State | Audio | Photo | Custom Command |
|---|---|---|---|
| Not authenticated | No | No | No |
| Authenticated, link not ready | No | No | No |
| Authenticated, link ready, scene not built | No | No | No |
| Authenticated, link ready, customView and view running | Yes | Yes | No |
| Authenticated, link ready, customApp and app launched | Yes | Yes | Yes |
“Scene built” should be judged using customViewRunningEventPublisher, app foreground/background, page-name events, etc. (follow the current RGCxrClient version). Strict prerequisites for Custom Command are described in “Custom Command”.
Sample entry points (typical)
The main view controller (commonly named ViewController.swift in docs) demonstrates capability buttons and event bindings. Replace it with the actual file names in ios_cxr_l_sample.