SDK · Swift/iOS

Pure-Swift client SDK for the imcore IM server. WebSocket + JSON, built on URLSessionWebSocketTask (zero dependencies). Works on iOS 13+, macOS 10.15+, tvOS 13+, watchOS 6+.

Add it (Swift Package Manager)

.package(path: "../path/to/clients/swift") // or a git URL
// target dependency: .product(name: "ImcoreSDK", package: "ImcoreSDK")

Usage

import ImcoreSDK

let im = ImcoreClient(
    url: "wss://your-host/acc",
    auth: AuthConfig(token: "<jwt>", login: LoginPayload(userId: "1001", userName: "alice"))
)

// Observe pushes and status with AsyncStreams:
Task { for await msg in im.events("chat_message") { print("msg", msg) } }
Task { for await s in im.statusStream() { print("status", s) } }       // idle/connecting/open/authenticated/closed
Task { for await _ in im.reconnectedStream() { /* re-pull conversations + cursor history */ } }

// connect() returns AFTER the server acknowledges login, and THROWS if login is
// refused (e.g. bad token) — always guard it. (All `try await` calls below must
// run inside an `async throws` context such as this do/catch or a Task.)
do {
    try await im.connect()

    _ = try await im.dm.send(targetUserId: "1002", text: "hi")
    let queued = try await im.dm.sendQueued(targetUserId: "1002", text: "works offline")
    print("\(queued.status) \(queued.tempId)")

    let history = try await im.dm.history(targetUserId: "1002", limit: 20)
    let cache = await im.cache
    let cached = await cache.getMessages("dm:1001:1002")

    _ = try await im.push.register(
        deviceId: "<stable-device-id>",
        platform: "ios",
        pushToken: "<apns-token>",
        vendor: "apns",
        appId: "<bundle-id>"
    )

    // Escape hatch for any command not yet wrapped:
    _ = try await im.request("chat_group_create", ["name": "team"])
    await im.send("chat_dm_typing", ["targetUserID": "1002"])  // fire-and-forget, non-throwing
} catch {
    print("imcore error: \(error)")
}

Scope (v1)

Transport core + seq-correlated request/response + login-ack-gated connect + typed DM/group/room/community send/receive/history + local message/conversation cache + tempID-backed offline send queue + push device registration wrapper. Not included: media upload helpers, E2EE, SwiftUI wrappers.

Development

cd clients/swift
swift build
swift test          # unit tests (fake channel + test scheduler, no server)

# Integration test against a live server:
IMCORE_TEST_WS_URL=wss://host/acc IMCORE_TEST_WS_TOKEN=<jwt> \
IMCORE_TEST_USER_ID=1001 IMCORE_TEST_PEER_ID=1002 swift test --filter IntegrationTests