This guide explains how to integrate the iOS SDK in license mode for device management and authentication. The multimodal SDK supports the license billing mode and two access modes: semi-managed and fully-managed.
1. Modes
To use the multimodal interaction development kit in the License billing mode, integrate the License SDK. For details, see Section 4.
1.1. Semi-hosted mode
Use case: You have your own cloud service and can manage and authenticate your devices. A two-way communication channel exists between your cloud service and devices.
-
Server-side development:
- See the Cloud API development guide to integrate with the cloud APIs. This service provides APIs for device registration and for obtaining a token.
-
Device-side development:
- Call the
genRegisterReqAPI of the SDK to obtain a signature for device registration. - After obtaining the signature, call your own cloud service to register the device. Your cloud service must integrate the POP SDK.
- After device registration is complete, call the
writeDeviceInfoAPI of the SDK to write the device information. - Call the
genGetTokenReqAPI of the SDK to obtain the data signature for the access token. - Call the
getTokenAPI of the SDK to obtain the decrypted service interaction token. Use this token for service interactions.
- Call the
1.2. Fully-hosted mode
Use case: You do not have a cloud service and cannot manage devices. Alibaba Cloud performs device management and authentication.
-
Server-side development:
- None
-
Device-side development:
- Call the
deviceRegisterAPI of the SDK to register the device. - Call the
getTokenAPI of the SDK to obtain the service interaction token. Use this token for service interactions.
- Call the
2. Prerequisites
- Before you use license mode, create an application on the Model Studio console and purchase a license.
- The SDK generates a unique device identifier and stores it in the keychain to prevent duplicate device registrations. You can retrieve this identifier by calling
DeviceInfoUtils.shared.getDeviceId(). You must either use the logic provided by the SDK to obtain thedeviceNameor ensure its uniqueness in your own implementation.
3. API
3.1. SDK initialization initialize
This method initializes the SDK for both semi-managed and fully-managed modes.
Parameters
Parameter | Type | Required | Description |
|---|---|---|---|
appId | String | Yes | The application ID. The Model Studio console generates this ID when you create an application. |
appSecret | String | Yes | The application secret. The Model Studio console generates this secret when you create an application. |
deviceName | String | Yes | The device name. You can use the device's Wi-Fi MAC address or a unique serial number. |
callBack | InitCallBack | Yes | The SDK initialization callback. Refer to the |
InitCallBack object
Return value | Method name | Description |
|---|---|---|
void | success() | Called when initialization is successful. |
void | fail(ResultError error) | Called when initialization fails. The |
ResultError object
Parameter | Type | Required | Description |
|---|---|---|---|
code | int | No | The error code. |
message | String | No | A human-readable error description. |
3.2. Semi-hosted mode
3.2.1. Device registration APIs
3.2.1.1. Generate device registration request: genRegisterReq
Input parameters:Parameter | Type | Required | Description |
|---|---|---|---|
appId | String | Yes | The application ID, generated after you create an application in the Model Studio console. |
deviceName | String | Yes | A unique name for the device. Use its Wi-Fi MAC address or serial number. |
payMode | String | Yes | The billing method. Valid values: |
reqNonce | String | Yes | A 26-character nonce for the request. |
requestTime | String | Yes | The request timestamp, in milliseconds. |
Parameter | Type | Required | Description |
|---|---|---|---|
success | boolean | Yes | Indicates whether the request was successful. |
code | int | No | The error code returned if the request fails. |
message | String | No | The error message returned if the request fails. |
data | String | No | The signature required to call the POP API for device registration. |
3.2.1.2. Write device registration information: writeDeviceInfo
The response from the device registration POP API must be passed to the device-side SDK to write the device information. Input parameters:Parameter | Type | Required | Description |
|---|---|---|---|
appId | String | Yes | The application ID, generated after you create an application in the Model Studio console. |
deviceName | String | Yes | A unique name for the device. Use its Wi-Fi MAC address or serial number. |
reqNonce | String | Yes | The nonce from the original registration request. |
rspNonce | String | Yes | A 26-character nonce from the server response. |
responseTime | String | Yes | The timestamp from the server response, in milliseconds. |
signature | String | Yes | YOUR_SIGNATURE |
Parameter | Type | Required | Description |
|---|---|---|---|
success | boolean | Yes | Indicates whether the request was successful. |
code | int | No | The error code returned if the request fails. |
message | String | No | The error message returned if the request fails. |
data | String | No | Not used. |
3.2.2. APIs for obtaining an access token
3.2.2.1. Generate access token request: genGetTokenReq
Input parameters:Parameter | Type | Required | Description |
|---|---|---|---|
nonce | String | Yes | A 26-character nonce for the request. |
appId | String | Yes | The application ID, generated after you create an application in the Model Studio console. |
deviceName | String | Yes | A unique name for the device. Use its Wi-Fi MAC address or serial number. |
payMode | String | Yes | The billing method. Valid values: |
tokenType | String | Yes | The type of token to request. The only currently supported value is The |
requestTime | String | Yes | The request timestamp, in milliseconds. |
Parameter | Type | Required | Description |
|---|---|---|---|
success | boolean | Yes | Indicates whether the request was successful. |
code | int | No | The error code returned if the request fails. |
message | String | No | The error message returned if the request fails. |
data | String | No | The signature required to call the server-side API to obtain an access token. |
3.2.2.2. Extract access token: getToken
Input parameters:Parameter | Type | Required | Description |
|---|---|---|---|
appId | String | Yes | The application ID, generated after you create an application in the Model Studio console. |
deviceName | String | Yes | A unique name for the device. Use its Wi-Fi MAC address or serial number. |
reqNonce | String | Yes | The nonce from the original access token request. |
rspNonce | String | Yes | A 26-character nonce from the server response. |
responseTime | String | Yes | The timestamp from the server response, in milliseconds. |
signature | String | Yes | YOUR_SIGNATURE |
Parameter | Type | Required | Description |
|---|---|---|---|
success | boolean | Yes | Indicates whether the request was successful. |
code | int | No | The error code returned if the request fails. |
message | String | No | The error message returned if the request fails. |
data | String | No | The resulting access token. |
3.3. Fully managed mode
3.3.1. Check device registration: deviceIsRegistered
Parameters:
None
Returns:
Returns true if the device is registered, or false otherwise.
Code example:
3.3.2. Register a device: deviceRegister
Parameters:
Parameter | Type | Required | Description |
|---|---|---|---|
params | Object | Yes | Device registration parameters. For details, see the |
callBack | DeviceRegisterCallBack | Yes | The callback that handles the device registration result. |
Parameter | Type | Required | Description |
|---|---|---|---|
nonce | String | Yes | A 26-character random string. |
appId | String | Yes | The application ID, generated by Model Studio when you create an application in the console. |
workspaceId | String | No | The workspace ID. Required only when registering a device using a workspace quota. |
deviceName | String | Yes | A unique device name, such as its Wi-Fi MAC address or serial number. |
requestTime | String | Yes | The request timestamp, in milliseconds. |
payMode | String | Yes | The billing method. Set to |
3.3.3. Get multimodal interaction token: getToken
Parameters:
Parameter | Type | Default | Required | Description |
|---|---|---|---|---|
params | Object | - | Yes | Parameters for getting a token. For details, see the |
callBack | GetTokenCallBack | - | Yes | The callback that handles the token retrieval result. For details, see the |
Parameter | Type | Default | Required | Description |
|---|---|---|---|---|
nonce | String | - | Yes | A 26-character random string. |
appId | String | - | Yes | The application ID, generated by Model Studio when you create an application in the console. |
apiKey | String | - | Yes | The API key. Create one in Key Management on the Model Studio console. |
deviceName | String | - | Yes | The unique identifier of the device. |
requestTime | String | - | Yes | The request timestamp, in milliseconds. |
payMode | String | - | Yes | The billing method. Set to |
tokenType | String | - | Yes | The type of token to request. Only MMI: multimodal interaction token |
3.4. Get license signatures
Input parameters:
Parameter | Type | Default | Required | Description |
|---|---|---|---|---|
params | Object | - | Yes | Parameters for device authentication. See the |
Parameter | Type | Default | Required | Description |
|---|---|---|---|---|
appId | String | - | Yes | The application ID. The Model Studio console provides this ID after you create an application. |
deviceName | String | - | Yes | The unique device identifier. |
taskId | String | - | Yes | The client generates this unique identifier to track task execution in the task pipeline. A 36-character UUID is recommended, for example: "f894c16f-f20e-4c1d-837e-89e0fbc63a43". |
Parameter | Type | Default | Description |
|---|---|---|---|
timestamp | String | - | The current timestamp in milliseconds. |
license_info | String | - | The signature for the license information. |
device_info | String | - | The signature for the device information. |
3.5. deviceReset
Note: After resetting a device in the Model Studio console, you must call the SDK's deviceReset API before registering it again.
Parameters:
None
Return value:
A boolean. Returns true if the reset was successful.
Example:
4. Integrate dependency library
Reference the MultimodalDialogTongyiMetathings.framework from the latest iOS SDK.
5. Multimodal SDK integration
- Before starting a session, initialize the tongyimetathings SDK and check if the device is registered. If not, register the device. For details, see the sample integration project.
- After initializing the SDK and registering the device, get a multimodal session token. See sections 2.1 and 2.3 for the required interfaces. Set the
apiKeyparameter to thedashTokenvalue returned by thegetTokeninterface. See the sample project for details.
- When creating a session, pass the license billing identifier. See the following code for a reference implementation: