CXR-L(EN)
CXR-L(EN)
IntroductionQuick StartDevelopment Flow & State-MachineTerms and Abbreviations
Feature Development
Version HistoryAndroid
iOS
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.plisthas configured the URL Scheme and therokidaiquery whitelist.AppDelegate/SceneDelegatecallsCxrClient.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.
Recommended flow
- User taps the “Authorize” button → call
authenticate.scopesshould match the business (commonly includes string identifiers such as device control and audio; follow the actual SDK docs). - Handle
.success(let (token, _))/.failurein thecompletion. - Subscribe to
statePublisherand only enable connection/capability entries after anAuthenticated-equivalent state. - 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)
| Action | Common location |
|---|---|
| Start auth | Button handler in ViewController (e.g., authButtonTapped) |
| URL callback | AppDelegate.swift, SceneDelegate.swift |
If class names differ in ios_cxr_l_sample, follow the actual Swift files.