XuqmGroup-Web/docs-site/docs/ios/index.md
XuqmGroup dadedbc4df feat: add VitePress docs-site with full SDK integration guides
- Add docs-site workspace (VitePress 1.5.0) with Android/iOS/RN/Vue3/HarmonyOS/Server docs
- Update Dockerfile to build and serve docs under /docs/
- Add /docs/ location block to Nginx config
- Add docs-site to yarn workspaces

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-24 15:35:24 +08:00

4.1 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_id",
    appSecret:  "your_app_secret",
    apiBaseUrl: "https://sentry.xuqinmin.com",
    imWsUrl:    "wss://sentry.xuqinmin.com/ws/im",
    debug:      false
)

2. IM 登录与监听消息

import XuqmIM

// 登录appId 已在 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}