On this page

Chat object

The Chat object is your entry point to the Chat SDK after initialization. Use the Chat object to create and manage channels, users, messages, memberships, and other entities.

Key capabilities:

  • Create and delete channels and users
  • Track user presence across channels
  • Send custom events
  • Access the underlying Swift SDK

Properties

The ChatImpl class implements the Chat protocol and takes the following properties:

1public final class ChatImpl {
2 public let pubnub: PubNub
3 public let config: ChatConfiguration
4}
ParameterDescription
pubnub
Type: PubNub
Initialized instance of the PubNub Swift SDK.

pubnub lets you access any Swift SDK method. For example, if you want to call a method available in the App Context API, you'd use chat.pubnub.getAllUUIDMetadata().
 → configuration
Type: PubNubConfiguration
Mandatory PubNub configuration parameters.
    → publishKey
Type: String
Specifies the key used to publish messages on a channel.
    → subscribeKey
Type: String
Specifies the key used to subscribe to a channel.
    → userId
Type: String
Unique User ID that becomes your app's current user. It's a string of up to 92 characters that identifies a single client (end user, device, or server) that connects to PubNub. Based on User ID, PubNub calculates pricing for your apps' usage. User ID should be persisted and remain unchanged. If you don't set userId, you won't be able to connect to PubNub.
config
Type: ChatConfiguration
ChatConfiguration contains chat app configuration settings, such as saveDebugLog or typingTimeout that you provide when initializing your chat app with the init() method. You can later directly access these properties, like: chat.storeUserActivityInterval.

ChatConfiguration includes these properties:

1public struct ChatConfiguration {
2 public var logLevel: LogLevel
3 public var typingTimeout: Int
4 public var storeUserActivityInterval: Int
5 public var storeUserActivityTimestamps: Bool
6 public var pushNotificationsConfig: PushNotificationsConfig
7 public var rateLimitFactor: Int
8 public var rateLimitPerChannel: [ChannelType: Int64]
9 public var customPayloads: CustomPayloads?
10}

PushNotificationsConfig includes these properties:

1public struct PushNotificationsConfig {
2 public var sendPushes: Bool
3 public var deviceToken: String?
4 public var deviceGateway: PubNub.PushService
5 public var apnsTopic: String?
6 public var apnsEnvironment: PubNub.PushEnvironment
7}

To initialize the Swift Chat SDK, you must provide two parameters: subscribeKey, and userId, while all other settings (mentioned above) are optional. Read the Configuration page for details.

Methods

You can call the following methods on the Chat object.

Click on each method for more details.

Use case

For example, you can use the Chat object methods to:

Last updated on