Docs

Swift: Realtime

Join channels, send and receive messages, follow connection status and catch up after a reconnect with the Swift SDK.

Updated Oct 24, 2026

Join channels, send and receive messages, follow connection status and catch up after a reconnect. Every call runs as the client's signed-in user, so your project's policies and row-level security apply. Types and members are listed in source order; each one links to its HTTP endpoint where it maps to one.

#Types and members

RealtimeStatus

The same states as the TypeScript and Dart clients: connecting (first attempt), live, reconnecting (dropped, retrying with backoff) and closed (closed by you, or refused: signed out, not allowed, misconfigured).

public enum RealtimeStatus: Sendable, Equatable

Values: connecting, live, reconnecting, closed.

RealtimeStatus.open

A property.

public static var open: RealtimeStatus

SovariaRealtime

Realtime channels. publish and presence work over HTTP; channel(_:) opens a WebSocket that delivers messages and reconnects with backoff. The token never goes in the URL — a one-time ticket does.

public final class SovariaRealtime: @unchecked Sendable

SovariaRealtime.channel

Open a channel and receive its messages.

public func channel(_ name: String, onMessage: @escaping @Sendable ([String: Any]) -> Void,
                    onStatus: (@Sendable (RealtimeStatus) -> Void)? = nil,
                    catchUp: Bool = true,
                    onGap: (@Sendable (RealtimeGap) -> Void)? = nil) -> RealtimeChannel

Keep the returned object; call close() when done.

catchUp: after a reconnect, deliver the messages published while the socket was down (from the channel's replay history) — in order, once each — before new ones. onGap: messages that were missed and can't be recovered (older than the retained history, or the history couldn't be read); reload state when it fires.

SovariaRealtime.publish

Publish to a channel over HTTP (no socket needed).

public func publish(_ channel: String, _ payload: [String: Any]) async throws

SovariaRealtime.replay

Messages after after (by stream_seq), oldest first: ["events": [...]].

public func replay(_ channel: String, after: Int = 0, limit: Int = 200) async throws -> Any?

SovariaRealtime.presence

Who is in a channel right now.

public func presence(_ channel: String) async throws -> Any?

SovariaRealtime.closeAll

public func closeAll()

RealtimeChannel

One open realtime channel. Reconnects on drop with capped backoff until close(). A WebSocket ping goes out every 30 s; a socket that answers none within 10 s is treated as dead and reopened, so a connection cut by NAT or radio sleep no longer sits "open" for minutes while messages are lost (SDK2-M13).

public final class RealtimeChannel: NSObject, @unchecked Sendable

RealtimeChannel.name

A property.

public let name: String

RealtimeChannel.send

Publish a message to everyone on the channel.

public func send(_ payload: [String: Any]) async throws

RealtimeChannel.close

public func close()

RealtimeGap

Messages fromSeq...toSeq (by stream_seq) were missed and can't be recovered; toSeq is nil when the history couldn't be read. reason: not_retained or replay_failed. Reload state from the source of truth.

public struct RealtimeGap: Sendable, Equatable

RealtimeGap.fromSeq

A property.

public let fromSeq: Int

RealtimeGap.toSeq

A property.

public let toSeq: Int?

RealtimeGap.reason

A property.

public let reason: String