Chat SDKs iOS v3
Chat SDKs iOS
Chat SDKs
iOS
Version 3
Sendbird Chat SDK v3 for iOS is no longer supported as a new version is released. Check out our latest Chat SDK v4

Event delegate

Copy link

Sendbird Chat SDK for iOS provides three types of event delegates for your client apps: channel delegate, user event delegate, and connection delegate. Through the channel delegate and user event delegate, Sendbird server notifies client apps of events that happen on the channels and users. When the client app is disconnected from the server, the SDK tries to reconnect to the server and notifies the client app of the result through the connection delegate.

With event callbacks provided by channel delegate and user event delegate, you can write the event-related processing code you want to execute. For example, the channel delegate's channel:didReceiveMessage: method is called when a message has been received in a channel. This callback receives SBDBaseChannel and SBDBaseMessage objects as parameters, which contain new information on the channel and message.

The Chat SDKs interact with our server through persistent WebSocket connections and multi-thread processing, receiving callbacks of asynchronous events of channels, users, and reconnect process of client apps through delegates in real-time. This allows you to track the events and implement your own chat features associated with those events.


Add and remove a channel delegate

Copy link

To receive and retrieve information about certain events happening in the channels from Sendbird server, you need to add a SBDChannelDelegate with its UNIQUE_DELEGATE_ID by calling the addChannelDelegate:identifier: method. The UNIQUE_DELEGATE_ID is a unique identifier you should declare to register multiple concurrent delegates.

Note: If you want to keep informed of changes related to the channels and notify other users' client apps of those changes, define and register multiple channel delegates to each view controller.

List of open channel events

Copy link
MethodInvoked whenNotified devices

channel:didReceiveMessage:

A message has been received in an open channel.

All devices where client apps with the channel are in the foreground, except the device that sent the message.

channel:didUpdateMessage:

A message has been updated in an open channel.

All devices where client apps with the channel are in the foreground, except the device where the message was updated.

channel:messageWasDeleted:

A message has been deleted in an open channel.

All devices where client apps with the channel are in the foreground, including the device where the message was deleted.

channel:didReceiveMention:

A user has been mentioned in a message sent in an open channel.

All devices of mentioned users (up to 10) in the channel, including the device that was used to mention other users.

channelWasChanged:

One of the following open channel properties has been changed: name, cover image, data, custom type, or operators.

All devices that are connected to the changed channel, including the device where the channel was changed.

channelWasDeleted:channelType:

An open channel has been deleted.

All devices where client apps with the channel are in the foreground, including the device where the channel was deleted.

channelWasFrozen:

An open channel has been frozen.

All devices where client apps with the channel are in the foreground, including the device where the channel was frozen.

channelWasUnfrozen:

An open channel has been unfrozen.

All devices where client apps with the channel are in the foreground, including the device where the channel was unfrozen.

channel:createdMetaData:

A metadata for an open channel has been created.

All devices where client apps with the channel are in the foreground, including the device where the metadata was created.

channel:updatedMetaData:

A metadata for an open channel has been updated.

All devices where client apps with the channel are in the foreground, including the device where the metadata was updated.

channel:deletedMetaDataKeys:

A metadata for an open channel has been deleted.

All devices where client apps with the channel are in the foreground, including the device where the metadata was deleted.

channel:createdMetaCounters:

A metacounter for an open channel has been created.

All devices where client apps with the channel are in the foreground, including the device where the metacounter was created.

channel:updatedMetaCounters:

A metacounter for an open channel has been updated.

All devices where client apps with the channel are in the foreground, including the device where the metacounter was updated.

channel:deletedMetaCountersKeys:

A metacounter for an open channel has been deleted.

All devices where client apps with the channel are in the foreground, including the device where the metacounter was deleted.

channel:userDidEnter:

A user has entered an open channel.

All devices where client apps with the channel are in the foreground, including the device that the user entered that channel.

channel:userDidExit:

A user has exited an open channel.

All devices where client apps with the channel are in the foreground, except the device that the user exited that channel.

channel:userWasMuted:

A user has been muted in an open channel.

All devices where client apps with the channel are in the foreground, including the device where the user was muted.

channel:userWasUnmuted:

A user has been unmuted in an open channel.

All devices where client apps with the channel are in the foreground, including the device where the user was unmuted.

channel:userWasBanned:

A user has been banned from an open channel.

All devices where client apps with the channel are in the foreground, including the device where the user was banned.

channel:userWasUnbanned:

A user has been unbanned from an open channel.

All devices where client apps with the channel are in the foreground, including the device where the user was unbanned.

channelDidChangeParticipantCount:

One or more open channels' participant count has changed.

All connected devices where client apps have the affected open channels in their channel list.

List of group channel events

Copy link
MethodInvoked whenNotified devices

channel:didReceiveMessage:

A message has been received in a group channel.

All devices where client apps with the channel are in the foreground, except the device that sent the message.

channel:didUpdateMessage:

A message has been updated in a group channel.

All devices where client apps with the channel are in the foreground, except the device where the message was updated.

channel:messageWasDeleted:

A message has been deleted in a group channel.

All devices where client apps with the channel are in the foreground, including the device where the message was deleted.

channel:didReceiveMention:

A user has been mentioned in a message sent in a group channel.

All devices of mentioned users (up to 10) in the channel, except the device that was used to mention other users.

channel:updatedReaction:

A message reaction has been updated in a group channel.

All devices where client apps with the channel are in the foreground, including the device that reacted to the message.

channelWasChanged:

One of the following group channel properties has been changed: distinct, push notification preferences, last message (except when the silent admin message), unread message count, name, cover image, data, or custom type.

All devices that are connected to the changed channel, including the device where the channel was changed.

channelWasDeleted:channelType:

A group channel has been deleted.

All devices where client apps with the channel are in the foreground, including the device where the channel was deleted.

channelWasFrozen:

A group channel has been frozen.

All devices where client apps with the channel are in the foreground, including the device where the channel was frozen.

channelWasUnfrozen:

A group channel has been unfrozen.

All devices where client apps with the channel are in the foreground, including the device where the channel was unfrozen.

channel:createdMetaData:

A metadata for a group channel has been created.

All devices where client apps with the channel are in the foreground, including the device where the metadata was created.

channel:updatedMetaData:

A metadata for a group channel has been updated.

All devices where client apps with the channel are in the foreground, including the device where the metadata was updated.

channel:deletedMetaDataKeys:

A metadata for a group channel has been deleted.

All devices where client apps with the channel are in the foreground, including the device where the metadata was deleted.

channel:createdMetaCounters:

A metacounter for a group channel has been created.

All devices where client apps with the channel are in the foreground, including the device where the metacounter was created.

channel:updatedMetaCounters:

A metacounter for a group channel has been updated.

All devices where client apps with the channel are in the foreground, including the device where the metacounter was updated.

channel:deletedMetaCountersKeys:

A metacounter for a group channel has been deleted.

All devices where client apps with the channel are in the foreground, including the device where the metacounter was deleted.

channelWasHidden:

A group channel has been hidden from the list.

All devices of a user who hided the channel.

channel:didReceiveInvitation:inviter:

A user has been invited to a group channel.

All devices where client apps with the channel are in the foreground, including the device of a user who received an invitation.

channel:didDeclineInvitation:inviter:

A user has declined an invitation to a group channel.

All devices where client apps with the channel are in the foreground, including the device of a user who declined an invitation.

channel:userDidJoin:

A user has joined a group channel.

All devices where client apps with the channel are in the foreground, including all devices of the user who joined the channel, and except the devices of users who haven't accepted invitations.

channel:userDidLeave:

A user has left a group channel.

All devices where client apps with the channel are in the foreground, including all devices of the user who left the channel, and except the devices of users who haven't accepted invitations.

channelDidUpdateDeliveryReceipt:

A message has been delivered in a group channel.

All devices where client apps with the channel are in the foreground, and except the device where the message was marked as delivered and has invoked this event.

channelDidUpdateReadReceipt:

A user has read a specific unread message in a group channel.

All devices where client apps with the channel are in the foreground, including all devices of the users who are invited to the channel, and except the device of the user who read the unread message.

channelDidUpdateTypingStatus:

A user starts typing a message to a group channel.

All devices where client apps with the channel are in the foreground, except the devices of the users who are invited to the channel, and except all devices of the user who typed a message.

channelDidUpdateThreadInfo:

A reply message has been created or deleted from a thread.

All devices where client apps with the channel are in the foreground, including devices of all users who are in the message thread, and except the device of the user who created or deleted the reply message.

channel:userWasMuted:

A user has been muted in a group channel.

All devices where client apps with the channel are in the foreground, including the device where the user was muted.

channel:userWasUnmuted:

A user has been unmuted in a group channel.

All devices where client apps with the channel are in the foreground, including the device where the user was unmuted.

channel:userWasBanned:

A user has been banned from a group channel.

All devices where client apps with the channel are in the foreground, including the device where the user was banned.

channel:userWasUnbanned:

A user has been unbanned from a group channel.

All devices where client apps with the channel are in the foreground, including the device where the user was unbanned.

channelDidChangeMemberCount:

One or more group channels' member count has changed.

All connected devices where client apps have the affected group channels in their channel list.

The following code shows a full set of supported event callbacks with their parameters and how to add a channel delegate to the unique SBDMain instance.

SwiftObjective-C
// ViewController.swift
class ViewController: UIViewController, SBDConnectionDelegate, SBDUserEventDelegate, SBDChannelDelegate {
    func initViewController() {
        ...

        SBDMain.add(self as SBDChannelDelegate, identifier: UNIQUE_DELEGATE_ID)
        ...

    }

    func channel(_ sender: SBDBaseChannel, didReceive message: SBDBaseMessage) {
    }

    func channel(_ sender: SBDBaseChannel, didUpdate message: SBDBaseMessage) {
    }

    func channel(_ sender: SBDBaseChannel, messageWasDeleted messageId: Int64) {
    }

    func channel(_ channel: SBDBaseChannel, didReceiveMention message: SBDBaseMessage) {
    }

    func channelWasChanged(_ sender: SBDBaseChannel) {
    }

    func channelWasDeleted(_ channelUrl: String, channelType: SBDChannelType) {
    }

    func channelWasFrozen(_ sender: SBDBaseChannel) {
    }

    func channelWasUnfrozen(_ sender: SBDBaseChannel) {
    }

    func channel(_ sender: SBDBaseChannel, createdMetaData: [String : String]?) {
    }

    func channel(_ sender: SBDBaseChannel, updatedMetaData: [String : String]?) {
    }

    func channel(_ sender: SBDBaseChannel, deletedMetaDataKeys: [String]?) {
    }

    func channel(_ sender: SBDBaseChannel, createdMetaCounters: [String : NSNumber]?) {
    }

    func channel(_ sender: SBDBaseChannel, updatedMetaCounters: [String : NSNumber]?) {
    }

    func channel(_ sender: SBDBaseChannel, deletedMetaCountersKeys: [String]?) {
    }

    func channelWasHidden(_ sender: SBDGroupChannel) {
    }

    func channel(_ sender: SBDGroupChannel, didReceiveInvitation invitees: [SBDUser]?, inviter: SBDUser?) {
    }

    func channel(_ sender: SBDGroupChannel, didDeclineInvitation invitee: SBDUser?, inviter: SBDUser?) {
    }

    func channel(_ sender: SBDGroupChannel, userDidJoin user: SBDUser) {
    }

    func channel(_ sender: SBDGroupChannel, userDidLeave user: SBDUser) {
    }

    func channelDidUpdateDeliveryReceipt(_ sender: SBDGroupChannel) {
    }

    func channelDidUpdateReadReceipt(_ sender: SBDGroupChannel) {
    }

    func channelDidUpdateTypingStatus(_ sender: SBDGroupChannel) {
    }

    func channel(_ sender: SBDOpenChannel, userDidEnter user: SBDUser) {
    }

    func channel(_ sender: SBDOpenChannel, userDidExit user: SBDUser) {
    }

    func channel(_ sender: SBDBaseChannel, userWasMuted user: SBDUser) {
    }

    func channel(_ sender: SBDBaseChannel, userWasUnmuted user: SBDUser) {
    }

    func channel(_ sender: SBDBaseChannel, userWasBanned user: SBDUser) {
    }

    func channel(_ sender: SBDBaseChannel, userWasUnbanned user: SBDUser) {
    }

    func channelDidChangeMemberCount(_ channels: [SBDGroupChannel]) {
    }

    func channelDidChangeParticipantCount(_ channels: [SBDOpenChannel]) {
    }
}

The following code shows how to remove the channel delegate.

SwiftObjective-C
SBDMain.removeChannelDelegate(forIdentifier: UNIQUE_DELEGATE_ID)

Add and remove a user event delegate

Copy link

To receive information about events related to users connected to Sendbird server, you need to add a user event delegate (SBDUserEventDelegate) with its unique user-defined ID. If you want to keep informed of changes related to the users, define and register multiple user event delegates to each view controller.

List of user events

Copy link
MethodInvoked whenNotified devices

didUpdateTotalUnreadMessageCount:totalCountByCustomType:

A user has read messages in the joined group channels and there is an update on the total number of the user's unread messages.

The user's devices with running client apps. The devices will be notified with the total number of unread messages along with a collection of the number of unread messages by custom channel type.

Note: To add or remove didUpdateTotalUnreadMessageCount:totalCountByCustomType:, contact support on the Sendbird Dashboard.

The following code shows a full set of supported event callbacks with their parameters and how to add a user event delegate to the unique SBDMain instance.

SwiftObjective-C
// ViewController.swift
class ViewController: UIViewController, SBDConnectionDelegate, SBDUserEventDelegate, SBDChannelDelegate {
    func initViewController() {
        ...

        SBDMain.add(self as SBDUserEventDelegate, identifier: UNIQUE_DELEGATE_ID)
        ...

    }

    func didUpdateTotalUnreadMessageCount(_ totalCount: Int32, totalCountByCustomType: [String : NSNumber]?) {
    }
}

The following code shows how to remove the user event delegate.

SwiftObjective-C
SBDMain.removeUserEventDelegate(forIdentifier: UNIQUE_DELEGATE_ID)

Add and remove a connection delegate

Copy link

By registering a connection delegate (SBDConnectionDelegate) with its unique user-defined ID, you can detect changes in the connection status of a client app. If you want to keep informed of changes related to the connection with Sendbird server, define and register multiple connection delegates to each view controller.

List of connection events

Copy link
MethodInvoked whenNotified devices

didStartReconnection

SDK has started reconnecting to Sendbird server.

The device where connectWithUserId: was automatically called by the Chat SDK, or manually by the client app.

didSucceedReconnection

SDK has succeeded in reconnecting to Sendbird server.

The device that successfully reconnected to the server.

didFailReconnection

SDK has failed to reconnect to Sendbird server.

The device that failed to reconnect to the server.

didCancelReconnection

SDK has canceled to reconnect to Sendbird server.

The device that canceled to reconnect to the server.

The following code shows a full set of supported event callbacks and how to add a connection delegate to the unique SBDMain instance.

SwiftObjective-C
// ViewController.swift
class ViewController: UIViewController, SBDConnectionDelegate, SBDChannelDelegate {
    func initViewController() {
        ...

        SBDMain.add(self as SBDConnectionDelegate, identifier: UNIQUE_DELEGATE_ID)
        ...

    }

    func didStartReconnection() {
    }

    func didSucceedReconnection() {
    }

    func didFailReconnection() {
    }

    func didCancelReconnection() {
    }
}

The following code shows how to remove the connection delegate.

SwiftObjective-C
SBDMain.removeConnectionDelegate(forIdentifier: UNIQUE_DELEGATE_ID)