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. These instructions use Git or a locally built package; package registry releases are a separate step.
.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.
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 channel access reference for the protocol.
Verify your integration
- Subscribe to
notificationsin your app or the dashboard’s Live console. - Publish
message.sentto the same application and channel from your backend. - 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.
Legacy pusher:* and pusher_internal:* control names are retained where required by the protocol. Their presence alone does not imply drop-in compatibility with every Pusher client or server.