- 新增 Android SDK 使用文档,包含模块结构、集成方式和快速开始指南 - 添加 SDK API 重设计规范,统一初始化和登录接口设计 - 补充安全设计规范,完善 UserSig 鉴权和敏感数据处理方案 - 创建平台 REST API 规范,定义服务端到服务端的调用接口 - 添加离线推送架构设计,集成各大厂商推送服务与 IM 联动方案
4.0 KiB
4.0 KiB
iOS SDK 概览
版本:0.1.0 · 最低 iOS 版本:iOS 14 · 语言:Swift 5.9+
功能模块
| 模块 | 功能 |
|---|---|
| XuqmCore | 初始化、网络、鉴权 |
| XuqmIM | 单聊、群聊、消息收发(13 种类型) |
| XuqmPush | APNs 设备 Token 注册、通知处理 |
| XuqmUpdate | App 版本检查、RN Bundle 热更新 |
安装
Swift Package Manager(推荐)
在 Xcode → File → Add Package Dependencies 中输入:
https://github.com/xuqm/XuqmGroup-iOSSDK
或在 Package.swift 中添加:
dependencies: [
.package(url: "https://github.com/xuqm/XuqmGroup-iOSSDK", from: "0.1.0")
]
按需引入所需模块:
.target(
name: "MyApp",
dependencies: [
.product(name: "XuqmCore", package: "XuqmGroup-iOSSDK"),
.product(name: "XuqmIM", package: "XuqmGroup-iOSSDK"),
.product(name: "XuqmUpdate", package: "XuqmGroup-iOSSDK"),
]
)
快速接入
1. 初始化
在 AppDelegate.application(_:didFinishLaunchingWithOptions:) 中:
import XuqmCore
XuqmSDK.shared.initialize(
appKey: "your_app_key",
appSecret: "your_app_secret",
debug: false
)
2. IM 登录与监听消息
import XuqmIM
// 登录(appKey 已在 init 时指定)
try await ImSDK.shared.login(userId: "user_001", nickname: "张三")
// 监听事件
ImSDK.shared.addListener(self)
extension ViewController: ImEventListener {
func onConnected() { print("WS connected") }
func onMessage(_ msg: ImMessage) { /* 处理消息 */ }
func onDisconnected(reason: String?) { /* 断线 */ }
}
3. 发送消息
// 发文本
let sent = try await ImSDK.shared.sendMessage(
toId: "user_002",
chatType: .single,
msgType: .text,
content: "Hello!"
)
// 发图片(content 为 JSON 字符串)
let imgContent = try JSONSerialization.data(withJSONObject: [
"url": "https://cdn.example.com/img.jpg",
"width": 800, "height": 600
])
let sent = try await ImSDK.shared.sendMessage(
toId: "user_002", chatType: .single,
msgType: .image, content: String(data: imgContent, encoding: .utf8)!
)
4. 撤回消息
let revoked = try await ImSDK.shared.revokeMessage(messageId: msg.id)
5. 群聊
// 创建群组
let group = try await ImSDK.shared.createGroup(name: "我的群", memberIds: ["user_001", "user_002"])
// 订阅群消息
ImSDK.shared.subscribeGroup(groupId: group.id)
// 发送群消息
try await ImSDK.shared.sendMessage(
toId: group.id, chatType: .group, msgType: .text, content: "大家好"
)
6. 检查更新
import XuqmUpdate
// App 整包更新
let appInfo = try await UpdateSDK.shared.checkAppUpdate(currentVersionCode: 1)
if let info = appInfo, info.forceUpdate {
// 强制更新:跳转 App Store 或下载链接
UIApplication.shared.open(URL(string: info.downloadUrl ?? info.appStoreUrl!)!)
}
// RN Bundle 热更新
let bundle = try await UpdateSDK.shared.checkRNUpdate(moduleId: "home", currentVersion: "1.0.0")
if let bundle = bundle {
let data = try await UpdateSDK.shared.downloadBundle(url: bundle.downloadUrl)
// 缓存至本地,下次启动时由 BundleRuntime 加载
}
消息类型
| MsgType | 说明 | content 结构 |
|---|---|---|
.text |
纯文本 | String |
.image |
图片 | {url, width, height, thumbnailUrl?} |
.video |
视频 | {url, duration, thumbnailUrl, size} |
.audio |
语音 | {url, duration, size} |
.file |
文件 | {url, name, size, mimeType} |
.location |
位置 | {lat, lng, address, title} |
.custom |
自定义 | 任意 JSON |
.notify |
系统通知 | {title, content, level} |
.richText |
富文本 | {html} |
.callAudio |
语音通话信令 | {callId, action, callerName} |
.callVideo |
视频通话信令 | {callId, action, callerName} |
.forward |
转发 | {originalMsgId, originalContent, originalSender} |