From f140d8de3ab8436dd360a8e039ade8a87a5d62f0 Mon Sep 17 00:00:00 2001 From: XuqmGroup Date: Tue, 28 Apr 2026 16:08:06 +0800 Subject: [PATCH] =?UTF-8?q?feat(sample):=20=E6=B7=BB=E5=8A=A0=E7=A4=BA?= =?UTF-8?q?=E4=BE=8B=E5=BA=94=E7=94=A8=E7=9A=84=E6=A0=B8=E5=BF=83=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 实现环境配置管理,支持外部和本地主机模式切换 - 集成Demo API接口,包含登录、注册、文件上传等功能 - 构建附件处理仓库,支持图片、视频、音频和文件发送 - 开发认证仓库,管理用户会话和IM令牌刷新机制 - 添加语音录制功能,支持实时音频消息录制 - 创建依赖注入容器,统一管理应用组件实例 - 实现登录界面,提供用户认证交互功能 - 开发聊天界面,集成消息收发和媒体处理功能 --- Sources/XuqmSDK/Core/ApiClient.swift | 11 +++++++++++ Sources/XuqmSDK/Core/SDKConfig.swift | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/Sources/XuqmSDK/Core/ApiClient.swift b/Sources/XuqmSDK/Core/ApiClient.swift index 206b0b5..16ab211 100644 --- a/Sources/XuqmSDK/Core/ApiClient.swift +++ b/Sources/XuqmSDK/Core/ApiClient.swift @@ -45,11 +45,22 @@ public final class ApiClient: @unchecked Sendable { req.httpBody = try JSONEncoder().encode(b) } + if config.debug { + print("[XuqmSDK][HTTP] request", method, req.url?.absoluteString ?? path) + } + let (data, response) = try await session.data(for: req) guard let http = response as? HTTPURLResponse, (200..<300).contains(http.statusCode) else { + if config.debug, let http = response as? HTTPURLResponse { + print("[XuqmSDK][HTTP] response", http.statusCode, req.url?.absoluteString ?? path) + } throw URLError(.badServerResponse) } + if config.debug { + print("[XuqmSDK][HTTP] response", http.statusCode, req.url?.absoluteString ?? path) + } + let wrapper = try JSONDecoder().decode(ApiResponse.self, from: data) if let result = wrapper.data { return result diff --git a/Sources/XuqmSDK/Core/SDKConfig.swift b/Sources/XuqmSDK/Core/SDKConfig.swift index 997695b..61b2b2c 100644 --- a/Sources/XuqmSDK/Core/SDKConfig.swift +++ b/Sources/XuqmSDK/Core/SDKConfig.swift @@ -24,3 +24,21 @@ public struct SDKConfig: Sendable { self.debug = debug } } + +public extension SDKConfig { + static func development( + appId: String, + appSecret: String, + appKey: String? = nil, + debug: Bool = false + ) -> SDKConfig { + SDKConfig( + appId: appId, + appKey: appKey ?? appId, + appSecret: appSecret, + apiBaseURL: URL(string: "http://192.168.116.9:8081")!, + imWebSocketURL: URL(string: "ws://192.168.116.9:8082/ws/im")!, + debug: debug + ) + } +}