CXR-L(EN)
cxr-l-sdk · v1.0.1 · snapshot 2026-05-13· ↗ source

Authentication

iOS: Authentication

Scenario

Start authorization via CxrClient.shared.auth to obtain the token and auth state used by subsequent links. The authorization depends on Rokid AI App. The callback is triggered by the URL Scheme and is parsed by the SDK in the app delegate.

Prerequisites

  • You have completed “SDK Import”.
  • Info.plist has configured the URL Scheme and the rokidai query whitelist.
  • AppDelegate / SceneDelegate calls CxrClient.shared.handleOpenURL.

Core members (concept)

Using let client = CxrClient.shared as an example:

  • client.auth.authenticate(scopes:appName:completion:): start authentication.
  • client.auth.clearAuthentication(): clear login state (optional).
  • client.auth.eventPublisher: event stream for the auth process.
  • client.auth.statePublisher: auth state machine, used for button availability and UI hints.
  1. User taps the “Authorize” button → call authenticate. scopes should match the business (commonly includes string identifiers such as device control and audio; follow the actual SDK docs).
  2. Handle .success(let (token, _)) / .failure in the completion.
  3. Subscribe to statePublisher and only enable connection/capability entries after an Authenticated-equivalent state.
  4. On failure, provide retry and “clear authorization” actions.

Example skeleton

client.auth.authenticate(scopes: [“device_control”, “audio_stream”], appName:YourAppName) { result in
switch result {
case .success(let (token, _)):
// Persist or keep token in memory, then proceed to connection
print(“token length=\(token.count))
case .failure(let error):
print(“auth failed: \(error))
}
}

scopes and appName must follow what you agreed with the Rokid open platform.

Sample entry points (typical demo naming)

ActionCommon location
Start authButton handler in ViewController (e.g., authButtonTapped)
URL callbackAppDelegate.swift, SceneDelegate.swift

If class names differ in ios_cxr_l_sample, follow the actual Swift files.

Marcin Miazga