iOS/macOS SDK for WuKongIM real-time messaging. Add chat functionality to your app in minutes.
- Easy Integration: Simple API with async/await support
- Flexible Payloads: Send any JSON data using dictionary literals
- Auto Reconnection: Intelligent reconnection with exponential backoff
- Cross-Platform: iOS, macOS, tvOS, watchOS support
- Thread Safe: All operations are thread-safe
- iOS 13.0+ / macOS 12.0+ / tvOS 13.0+ / watchOS 6.0+
- Xcode 12.0+
- Swift 5.7+
Xcode:
- File → Add Package Dependencies
- Enter:
https://github.com/WuKongIM/WuKongEasySDK-iOS
Package.swift:
dependencies: [
.package(url: "https://github.com/WuKongIM/WuKongEasySDK-iOS.git", from: "1.0.0")
]pod 'WuKongEasySDK', '~> 1.0.0'import WuKongEasySDK
// 1. Configure and initialize
let config = try WuKongConfig(
serverUrl: "ws://your-server.com:5200",
uid: "user123",
token: "auth_token"
)
let sdk = WuKongEasySDK(config: config)
// 2. Set up event listeners
sdk.onConnect { _ in print("Connected!") }
sdk.onMessage { message in print("Received: \(message.payload)") }
sdk.onError { error in print("Error: \(error)") }
// 3. Connect
try await sdk.connect()
// 4. Send messages
let payload: MessagePayload = [
"type": 1,
"content": "Hello World!",
"timestamp": Date().timeIntervalSince1970
]
try await sdk.send(
channelId: "friend_id",
channelType: .person,
payload: payload
)Send any JSON data using dictionary literals:
// Text message
let textMessage: MessagePayload = [
"type": 1,
"content": "Hello World!"
]
// Image message
let imageMessage: MessagePayload = [
"type": 2,
"content": "Check this out!",
"image": [
"url": "https://example.com/image.jpg",
"width": 1920,
"height": 1080
]
]
// Custom message
let customMessage: MessagePayload = [
"type": 100,
"action": "game_invite",
"game_id": "chess_123"
]A SwiftUI example app is available in Examples/WuKongIMExample-Unified/:
- Real-time messaging with raw JSON payload display
- Connection management and event logging
- Cross-platform (iOS/macOS)
cd Examples/WuKongIMExample-Unified
./build.sh ios # Build for iOS
./build.sh macos # Build for macOSlet sdk = try WuKongEasySDK.create { builder in
try builder
.serverUrl("ws://your-server.com:5200")
.uid("user123")
.token("auth-token")
.connectionTimeout(30)
.enableDebugLogging(true)
.build()
}sdk.onError { error in
if let wkError = error as? WuKongError {
switch wkError {
case .authFailed(let message):
print("Auth failed: \(message)")
case .networkError(let message):
print("Network error: \(message)")
case .notConnected:
print("Not connected")
default:
print("Error: \(wkError.localizedDescription)")
}
}
}import SwiftUI
import WuKongEasySDK
@MainActor
class ChatManager: ObservableObject {
private let sdk: WuKongEasySDK
@Published var isConnected = false
@Published var messages: [Message] = []
init() {
let config = try! WuKongConfig(
serverUrl: "ws://your-server.com:5200",
uid: "user123",
token: "auth-token"
)
self.sdk = WuKongEasySDK(config: config)
sdk.onConnect { [weak self] _ in self?.isConnected = true }
sdk.onDisconnect { [weak self] _ in self?.isConnected = false }
sdk.onMessage { [weak self] message in self?.messages.append(message) }
}
func connect() async {
try? await sdk.connect()
}
func disconnect() {
sdk.disconnect()
}
}Apache License 2.0. See LICENSE file.