Client SDK

Realtime WebSocket Notifications for iOS & Swift

Add real-time WebSocket notifications to iOS and macOS apps with a native Swift SDK. Built on URLSessionWebSocketTask — no third-party WebSocket library needed. SPM-ready for iOS 13+ and macOS 10.15+.

SPM $ .package(url: "https://github.com/apinator-io/apinator-swift", from: "1.0.0")

Adding real-time WebSocket notifications to an iOS app is simple with Apinator's native Swift SDK. Built on Apple's URLSessionWebSocketTask, it opens a persistent WebSocket connection to Apinator's servers and delivers events directly to your SwiftUI views or UIKit controllers. No third-party WebSocket frameworks needed — pure Swift with Swift Package Manager distribution.

Quick Start

How to add WebSocket notifications to an iOS app with Swift

Add realtime features to your Swift app in a few steps.

01

Add the Swift package

Add the RealtimeSDK package to your Xcode project via Swift Package Manager.

// Package.swift .package( url: "https://github.com/apinator-io/apinator-swift", from: "1.0.0" )
02

Create a client and open a WebSocket connection

Initialize the client with your app key and call connect() to open a persistent WebSocket connection to Apinator.

import RealtimeSDK let client = RealtimeClient(appKey: "your-app-key") { options in options.cluster = "us" options.authEndpoint = "https://your-api.com/realtime/auth" } client.connect()
03

Subscribe to a WebSocket channel

Subscribe to a private channel and bind event handlers with the chainable API. Events arrive in real-time over the WebSocket connection.

let channel = client.subscribe("private-notifications") channel.bind("new-alert") { data in if let json = try? JSONSerialization.jsonObject( with: data.data(using: .utf8)! ) as? [String: Any] { print("Alert:", json) } }
04

Use presence for live users

Presence channels track who is online. Get member lists and member events.

let presence = client.subscribe("presence-room") // When subscription succeeds presence.bind("realtime:subscription_succeeded") { _ in print("Members:", presence.memberCount) }

Why Swift

Built for Swift developers

Native URLSession

Built on URLSessionWebSocketTask. No third-party WebSocket libraries needed. Works on iOS 13+ and macOS 10.15+.

Swift Package Manager

Add as a dependency via SPM. No CocoaPods or Carthage required. Clean dependency management.

Chainable API

Fluent method chaining: client.connect().subscribe("ch").bind("event") { data in ... }.

Auto-Reconnect

Exponential backoff reconnection with configurable max attempts. Your app stays connected.

How WebSocket notifications work in an iOS app

iOS apps typically receive background notifications through Apple Push Notification service (APNs), which requires a paid developer account, device registration, and a push notification provider. APNs works well for notifications delivered while the app is in the background, but it is not designed for real-time in-app updates — delivery latency can be several seconds, and there is no ordering guarantee.

For in-app real-time features — live feeds, chat messages, presence indicators, live auction bids — a persistent WebSocket connection is more appropriate. Apinator's Swift SDK opens and maintains a WebSocket connection using Apple's native URLSessionWebSocketTask and receives events in real-time as they are published from your backend. Unlike push notifications, this requires no APNs certificates, no device token registration, and no special app entitlements.

The SDK integrates naturally with SwiftUI through the ObservableObject pattern: bind incoming WebSocket events to @Published properties, and your views update automatically via Combine. It also handles auto-reconnect with exponential backoff, which is important on mobile where network changes (switching from WiFi to cellular) are common and should not require any code in your view layer.

Full Example

Full Example: Realtime WebSocket Notifications in SwiftUI

Complete WebSocket example: an ObservableObject that manages the persistent WebSocket connection and a SwiftUI view that displays live notifications via @Published.

RealtimeManager.swift
import Foundation import RealtimeSDK class RealtimeManager: ObservableObject { static let shared = RealtimeManager() private let client: RealtimeClient @Published var notifications: [String] = [] private init() { client = RealtimeClient(appKey: "your-app-key") { opts in opts.cluster = "us" opts.authEndpoint = "https://api.example.com/realtime/auth" } } func start() { let ch = client.connect().subscribe("private-alerts") ch.bind("new-alert") { [weak self] data in DispatchQueue.main.async { self?.notifications.append(data) } } } func stop() { client.disconnect() } }

Start building realtime Swift apps

Completely free. No credit card. No catch.