Build any realtime experience using Ably's Pub/Sub Cocoa SDK. Supported on all popular platforms and frameworks, including Swift and Objective-C.
Ably Pub/Sub provides flexible APIs that deliver features such as pub-sub messaging, message history, presence, and push notifications. Utilizing Ably's realtime messaging platform, applications benefit from its highly performant, reliable, and scalable infrastructure.
Find out more:
Everything you need to get started with Ably:
Ably aims to support a wide range of platforms. If you experience any compatibility issues, open an issue in the repository or contact Ably support.
The following platforms are supported:
| Platform | Support |
|---|---|
| iOS | >= 14 |
| macOS | >= 11 |
| tvOS | >= 14 |
Building the SDK requires Xcode 26 or later.
Important
Ably Cocoa SDK versions below 1.2.23 will be deprecated from November 1, 2025.
You can install Ably for iOS and macOS through Swift package manager. Upgrading from 1.x is covered by the migration guide.
Important
CocoaPods and Carthage are not supported from 2.0. Their last releases — the Ably pod and the
Carthage Ably.xcframework — are on the 1.x line, which receives security and critical fixes only.
To take 2.0 or later, move to Swift Package Manager.
To use the Ably LiveObjects plugin, see its installation notes below — it is available via Swift Package Manager only.
The Ably Pub/Sub SDK includes installation support for Swift Package Manager.
Swift Package Manager installation details.
To install the ably-pubsub-cocoa package in your Xcode project:
- Paste
https://github.com/ably/ably-pubsub-cocoain the Swift Packages search box. (Xcode project → Swift Packages… →+button) - Select the
AblyPubSubDeviceSDK for your target.
To install the ably-pubsub-cocoa package in another Swift package, add the following to your Package.Swift:
.package(url: "https://github.com/ably/ably-pubsub-cocoa", from: "2.0.0"),See Apple's adding package dependencies to your app guide for more detail.
The SDK ships a privacy manifest (PrivacyInfo.xcprivacy), which Xcode merges into your app's privacy report. It declares the Device ID data type, which is collected only if your app uses push notifications: the SDK generates a random device ID and sends it to Ably when it registers the device for push, or subscribes it to push channels. If your app doesn't use push notifications, the SDK doesn't send the device ID off the device, and you can leave Device ID off your App Store privacy label. The device ID is not used for tracking.
// Initialize Ably Realtime client
let clientOptions = ClientOptions(key: "your-ably-api-key")
clientOptions.clientId = "me"
let realtime = PubSubDevice.createClient(options: clientOptions)
// Wait for connection to be established
realtime.connection.on { stateChange in
if stateChange.current == .connected {
print("Connected to Ably")
// Get a reference to the 'test-channel' channel
let channel = realtime.channels.get("test-channel")
// Subscribe to all messages published to this channel
channel.subscribe { message in
print("Received message: \(message.data ?? "")")
}
// Publish a test message to the channel
channel.publish("test-event", data: "hello world!") { error in
guard error == nil else {
print("Error publishing message: \(error!.message)")
return
}
print("Message successfully published")
}
}
}In Swift, import AblyPubSubDeviceSwift to await operations such as attaching, publishing and entering presence instead of passing callbacks. Failures throw an ErrorInfo:
import AblyPubSubDeviceSwift
let channel = realtime.channels.get("test-channel")
try await channel.attach()
try await channel.publish("test-event", data: "hello world!")
try await channel.presence.enter("present")Ably LiveObjects provides realtime, collaborative data structures that automatically synchronize state across all connected clients. This repository contains the Ably LiveObjects plugin, which enables LiveObjects on top of the core Pub/Sub SDK.
The plugin is available via Swift Package Manager. There is no separate package or version to install: the plugin ships as a product of this package and is versioned and released as part of ably-pubsub-cocoa.
To install it in your Xcode project, add the ably-pubsub-cocoa package as above
and additionally select the AblyLiveObjects product for your target.
To install it in another Swift package, add the product to your target's dependencies:
.target(
name: "MyTarget",
dependencies: [
.product(name: "AblyPubSubDevice", package: "ably-pubsub-cocoa"),
.product(name: "AblyLiveObjects", package: "ably-pubsub-cocoa"),
]
)For usage, platform requirements, the example app and the migration guide for users of the standalone plugin package, see the LiveObjects README. For a comprehensive guide, check the LiveObjects documentation, starting with the Swift quickstart.
Read the CONTRIBUTING.md guidelines to contribute to Ably.
The CHANGELOG.md contains details of the latest releases for this SDK. You can also view all Ably releases on changelog.ably.com.
For help or technical support, visit Ably's support page or GitHub Issues for community-reported bugs and discussions.
