Initial configuration
Before building your chat app, you must initialize and configure the Chat SDK.
Start by signing into the Admin Portal or creating an account if you don't have one yet.
Then, create an app on the Admin Portal. You will need a PubNub app to get a keyset that consists of a Subscribe Key and a Publish Key. These keys will let you establish a connection between PubNub and the chat app you're going to create with the Chat SDK.
Limit of 3 keysets for Free tier accounts
Effective February 3, 2025, all Free tier accounts will be limited to a maximum of three keysets. If your account exceeds this limit, you must delete existing keysets to create new ones.
When you create a new app on the Admin Portal, the first set of demo keys is generated automatically, but a single app can have as many keysets as you like. We recommend that you create separate keysets for production and test environments.
Enable features on your keyset
Each keyset has its own configuration settings in the Admin Portal. To use some features in your chat app, you must enable appropriate settings on your app's keyset on the Admin Portal.
To use the Chat SDK, create or update users, track presence, and store messages in history, make sure App Context, Presence, and Message Persistence are enabled on your keyset.
Download the SDK
Download the SDK from any of the following sources:
Use Swift Package Manager
To integrate PubNub into your project using the Swift Package Manager specify PubNub in the dependencies list of your Package.swift
file:
dependencies: [
.package(url: "https://github.com/pubnub/swift-chat-sdk", exact: "0.11.0-dev")
]
Use Xcode
- Create or open your project inside Xcode.
- Navigate to File -> Add Package Dependencies.
- Search for
https://github.com/pubnub/swift-chat-sdk
. - From the Dependency Rule drop-down list, select Exact. In the version input field, type
0.11.0-dev
. - Click the Add Package button.
Initialize PubNub
Once you have a PubNub account and an app created on the Admin Portal, you can start initializing PubNub Client API context and establish account-level credentials.
To initialize PubNub with the Chat SDK:
-
Create a
ChatImpl
object, which takes the following parameters:Configuration Description pubNubConfiguration
An instance of the PubNub account configuration. You must provide at least the subscribeKey
anduserId
to connect to PubNub.chatConfiguration
An instance of chat-specific configuration required to implement advanced features, like typing indicator, user offline/online presence, push notifications, or client-side limiting that prevents spamming. -
Call the
initialize()
method on yourChatImpl
object.
// Chat SDK-specific configuration
public struct ChatConfiguration {
public var logLevel: LogLevel
public var typingTimeout: Int
public var storeUserActivityInterval: Int
public var storeUserActivityTimestamps: Bool
public var pushNotificationsConfig: PushNotificationsConfig
public var rateLimitFactor: Int
public var rateLimitPerChannel: [ChannelType: Int64]
public var customPayloads: CustomPayloads?
public init(
logLevel: LogLevel = .off,
typingTimeout: Int = 5,
storeUserActivityInterval: Int = 600,
show all 38 linesInput parameters
Parameter | Type | Description |
---|---|---|
pubNubConfiguration | PubNubConfiguration | Mandatory PubNub account configuration. |