We’re on Product Hunt (opens in a new tab)

Client SDK · iOS, macOS, tvOS & watchOS

Swift SDK

Swift 5.9+, iOS 15+, macOS 12+, tvOS 15+ or watchOS 8+. Uses Foundation with no third-party dependencies.

Install from GitHub

The SDK source is public on the main branch. Use the release installation instructions below; source branches can differ from published packages.

Installation
.package(url: "https://github.com/pubbio/sdk-swift.git", branch: "main")

Add this dependency to Package.swift and the Pubb library product to your target. In Xcode, use File → Add Package Dependencies, enter the repository URL, and select main. Pin a verified commit for reproducible builds.

Subscribe to events

Use your public app key from the Pubb dashboard. Subscribe before publishing a matching event from your trusted backend.

Realtime.swift
import Pubb

@MainActor
func startRealtime() throws -> Pubb {
    let pubb = try Pubb(key: "YOUR_PUBLIC_APP_KEY")
    pubb.onError = { print($0) }
    pubb.subscribe("notifications").bind("message.sent") { data in
        print(data["message"]?.string ?? "Message received")
    }
    pubb.connect()
    return pubb
}
// Retain the returned client. On teardown, call pubb.disconnect().

All SDK access and callbacks run on the main actor. Retain one client per owning screen or session, disconnect when appropriate for backgrounding, and avoid strong reference cycles in callbacks. Unexpected failures retry up to five times and restore subscriptions.

Private and presence channels

Pass Pubb.httpAuthorizer(endpoint:headers:) as the client's authorizer. Point it at your authenticated backend route; use the headers closure for current session credentials. Presence channels expose members and pubb:member_added / pubb:member_removed events.

Your backend receives socket_id and channel_name, checks the authenticated user’s access, and returns auth plus channel_data for presence. Derive the presence user ID from the session and forward the signed channel_data unchanged.

Keep the app secret on your trusted server. Public channels must not carry personal or restricted data. Read the WebSocket Protocol Reference for channel authorization and exact wire messages.

Client events

Applications can opt into scoped WebSocket publishing. The updated JavaScript and Unity clients accept a separate publishing permission; JavaScript and .NET server helpers issue it after your access checks. Other SDK releases can use the documented wire protocol. Read Client events for setup, expiry, revocation and acknowledgement semantics.

Verify your integration

  1. Subscribe to notifications in your app or the dashboard’s Live console.
  2. Publish message.sent to the same application and channel from your backend.
  3. Check the event payload, connection cleanup and recovery after a disconnect. Test denied access as well as successful private subscriptions.

The repositories include automated tests and examples. Verify end-to-end delivery with your own application before sending production traffic. Refetch durable state after reconnecting; missed events are not replayed.