简介
此模块定义了跨平台通用的基础类型,为 API 调用提供统一的错误处理和回调机制。
功能特性
回调机制:提供统一的完成回调闭包类型。
数据结构
CompletionHandler
提供基础类型定义,包括错误处理结构、回调闭包类型和响应式状态管理工具。
方法
onSuccess: 操作成功时调用。
fun onSuccess()
onFailure: 操作失败时调用。
fun onFailure(code: Int, desc: String)
参数名 | 类型 | 说明 |
code | Int | 错误码。 |
desc | String | 错误描述。 |
ExperimentalEventCallback
实验性事件回调,回传 roomID 和 JSON 负载。
ExperimentalAPICallback
实验性 API 调用完成回调,回传错误码、错误信息和引擎返回的 JSON 字符串。
ListResultCompletionHandler
列表结果完成回调接口。
用于返回分页列表的异步操作结果回调接口。
方法
onSuccess: 操作成功时调用,返回列表结果和游标。
fun onSuccess(result: List<T>,cursor: String)
参数名 | 类型 | 说明 |
result | List<T> | 结果列表。 |
cursor | String | 分页游标。 |
onFailure: 操作失败时调用。
fun onFailure(code: Int,desc: String)
参数名 | 类型 | 说明 |
code | Int | 错误码。 |
desc | String | 错误描述。 |
使用示例
// CompletionClosure 使用 Swift 的 Result 类型:// - .success(Void):操作成功// - .failure(ErrorInfo):操作失败func someAsyncOperation(completion: @escaping CompletionClosure) {// 异步操作...}someAsyncOperation { result inswitch result {case .success:print("操作成功")case .failure(let error):print("错误码:\\(error.code),错误信息:\\(error.message)")}}