Chat object

Once you initialize the Chat SDK and create its instance, you'll get immediate access to the Chat entity from which you can call the PubNub server.

To communicate with PubNub, you can use various methods. For example, you can use deleteChannel() to remove a given channel or wherePresent() to check which channels a given user is subscribed to.

By calling methods on the ChatImpl object, you create further objects like Channel, User, Message, Membership, ThreadChannel, and ThreadMessage. These objects also expose Chat API under various methods, letting you perform CRUD operations on messages, channels, users, the related user-channel membership, and many more.

Each of these entities comes with a set of "read-only" parameters you define when creating, modifying, and deleting specific channels, users, messages, or memberships in your chat app.

Properties

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

public final class ChatImpl {
public let pubnub: PubNub
public let config: ChatConfiguration
}
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:

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?
}

PushNotificationsConfig includes these properties:

public struct PushNotificationsConfig {
public var sendPushes: Bool
public var deviceToken: String?
public var deviceGateway: PubNub.PushService
public var apnsTopic: String?
public var apnsEnvironment: PubNub.PushEnvironment
}

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-related methods to:

Last updated on