ably-pubsub-cocoa

2.0.0

iOS, tvOS and macOS Objective-C and Swift client library SDK for Ably realtime messaging service
ably/ably-pubsub-cocoa

What's New

2.0.0

2026-10-29T19:15:44Z

The 2.0.0 release makes ably-cocoa a device-side SDK, for apps that run on an end user's device. A client is created through PubSubDevice.createClient, and every client it creates tells Ably that it runs on a device. That declaration determines how its traffic is counted: on an account billed by monthly active users, device traffic counts toward the total, the connection must carry a clientId, and that clientId is subject to a concurrency limit.

The repository is renamed to ably-pubsub-cocoa, and the package is distributed through Swift Package Manager only. In Swift, a new AblyPubSubDeviceSwift module adds async versions of channel and presence operations.

2.0 also brings the public API in line with the Ably client library specification: it renames types, removes the APIs deprecated in 1.x, and corrects types and nullability.

Below is an overview of the major changes in this release.

Please refer to the v2 migration guide for the full details, including a list of all breaking changes and instructions on how to address them.

Repository, package and distribution

  • Add the package from https://github.com/ably/ably-pubsub-cocoa. The old URL, https://github.com/ably/ably-cocoa, serves the 1.x line, which receives security and critical fixes only.
  • Swift Package Manager is the only distribution channel. 2.0 ships no CocoaPods pod and no Carthage framework, and both stay on the 1.x line.
  • The SDK is the AblyPubSubDevice product, which replaces Ably. The package also vends AblyLiveObjects, released at the same version.
  • In Swift, import AblyPubSubDeviceSwift. In Objective-C, import AblyPubSubDevice.

Creating clients

  • Create a client with PubSubDevice.createClient(options:), createClient(key:) or createClient(token:).
  • The client class's initializers are no longer public, and the createWithOptions:, createWithKey: and createWithToken: class factories are removed.
  • The SDK identifies itself to Ably as ably-pubsub-cocoa, where 1.x sent ably-cocoa. A client from PubSubDevice.createClient also sends a versionless ably-pubsub-device entry.

Swift API

  • Swift sees the SDK's types without the ART prefix: ARTClientOptions is ClientOptions, ARTErrorInfo is ErrorInfo, and so on. Objective-C keeps the prefix.
  • AblyPubSubDeviceSwift adds async versions of operations such as attach, publish and presence enter, which throw an ErrorInfo.

Client API naming

  • ARTRealtime is renamed ARTPubSubClient, and ARTRealtimeProtocol is renamed ARTPubSubProtocol.
  • ARTRest is renamed ARTHttpClient, along with ARTHttpChannel, ARTHttpChannels, ARTHttpPresence and ARTHttpAnnotations. These classes are now internal. An application reaches Ably through the realtime client.

Client options

  • endpoint replaces the environment, restHost and realtimeHost options, which are removed. A client that sets none of them connects to main.realtime.ably.net, with fallbacks at main.[a-e].fallback.ably-realtime.com.
  • realtimeRequestTimeout and maxMessageSize move from ARTDefault to ARTClientOptions, so each client can set its own. maxFrameSize is a new option.
  • With an empty fallbackHosts array, an unreachable host no longer fails the connection. The connection moves to DISCONNECTED and retries.

Types and nullability

  • ARTStats has no typed properties. Every statistic is in entries, keyed by its name.
  • extras is a dictionary on messages, presence messages and annotations.
  • ARTCrypto.getDefaultParams: takes an ARTCipherParamOptions, and a dictionary can no longer be passed as a channel's cipher.
  • ARTDevicePushDetails.state is an ARTDevicePushState enum.
  • ARTMessageVersion and ARTMessageAnnotations are immutable and Sendable.
  • Message.version, Message.annotations, Annotation.timestamp and the listener that subscribe returns are no longer optional. Message.connectionId is now optional.
  • When a system error stops an operation, the ErrorInfo has an Ably error code, and the system error is its underlying error.

Behaviour changes

  • channels.release() throws unless the channel is initialized, detached or failed. Detach a channel before releasing it.
  • Invalid arguments to history, stats, request and push listSubscriptions raise NSInvalidArgumentException, and those methods no longer return an error.
  • Subscribing on a channel in the FAILED state registers the listener.
  • The client falls back to another host after a DISCONNECTED with a 5xx error, or after a CloudFront error response.

Removed APIs

  • The members deprecated in 1.x: fallbackHostsUseDefault, ARTConnection.recoveryKey and ARTStats.intervalGranularity.
  • The publish overloads that take clientId or extras alongside name and data. Set them on a Message instead.
  • didAblyPushRegistrationFail:. Implement didUpdateAblyPush: instead.
  • ARTDataQueryError, ARTRealtimeHistoryError and ARTCustomRequestError.

Supported platforms changes

  • Support for macOS earlier than 12, iOS earlier than 15 and tvOS earlier than 15 has been dropped.
  • Building the SDK requires Xcode 26 or later (Swift 6.2).

Full Changelog

Ably Pub/Sub Cocoa Header Latest Version License

Ably Pub/Sub Cocoa SDK

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:


Getting started

Everything you need to get started with Ably:


Supported platforms

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.


Installation

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.

Swift Package Manager

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-cocoa in the Swift Packages search box. (Xcode project → Swift Packages… → + button)
  • Select the AblyPubSubDevice SDK 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.

Privacy manifest

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.


Usage

// 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")

LiveObjects

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.

Install LiveObjects

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.


Contribute

Read the CONTRIBUTING.md guidelines to contribute to Ably.


Releases

The CHANGELOG.md contains details of the latest releases for this SDK. You can also view all Ably releases on changelog.ably.com.


Support, feedback, and troubleshooting

For help or technical support, visit Ably's support page or GitHub Issues for community-reported bugs and discussions.

Description

  • Swift Tools 6.2.0
View More Packages from this Author

Dependencies

Last updated: Sun Nov 08 2026 07:49:06 GMT-1000 (Hawaii-Aleutian Standard Time)