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+.
.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.
Add the Swift package
Add the RealtimeSDK package to your Xcode project via Swift Package Manager.
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.
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.
Use presence for live users
Presence channels track who is online. Get member lists and member events.
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.
Related Docs
Read the core WebSocket guides
Related Use Cases
Explore realtime use cases
Start building realtime Swift apps
Completely free. No credit card. No catch.