Chat / iOS
Chat iOS v4
Chat iOS
Chat
iOS
Home
/
Chat
/
iOS
/
Event delegate
This is the new Docs for Chat SDK v4 for iOS. To see the previous Docs, click here.

Add or remove a channel delegate

To receive and retrieve information about events happening in channels from the Sendbird server, add a channel delegate with its UNIQUE_DELEGATE_ID by calling the add(_:identifier:) method. You should declare the UNIQUE_DELEGATE_ID when registering multiple concurrent delegates.

There are three types of channel delegates: BaseChannelDelegate, GroupChannelDelegate, and OpenChannelDelegate. The following tables show a list of channel delegates by channel type.

If you want to stay informed of changes related to channels and notify the changes to different client apps, define and register multiple channel delegates to each view controller.


Channel event types

List of open channel events

MethodInvoked whenNotified devices

channel(_:didReceive:)

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(_:didUpdate:)

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 to an open channel.

All devices of up to ten users mentioned in the channel, except 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:)

Metadata has been created for an open channel.

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

channel(_:updatedMetaData:)

Metadata of 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:)

Metadata of 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 has been created for an open channel.

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

channel(_:updatedMetaCounters:)

A metacounter of 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 of 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 participant 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 participant in an open channel has been muted.

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

channel(_:userWasUnmuted:)

A participant in an open channel has been unmuted.

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

channel(_:userWasBanned:)

A participant 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 participant 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(_:)

The participant count of one or more open channels has changed.

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

List of group channel events

MethodInvoked whenNotified devices

channel(_:didReceive:)

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(_:didUpdate:)

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 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:)

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:)

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:)

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.

channelDidUpdateDeliveryStatus(_:)

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.

channelDidUpdateReadStatus(_:)

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.


Add a channel event delegate

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

// ViewController.swift
class ViewController: UIViewController, GroupChannelDelegate {
    func initViewController() {
        SendbirdChat.add(self as GroupChannelDelegate, identifier: UNIQUE_DELEGATE_ID)
    }

    func channel(_ channel: BaseChannel, didReceive message: BaseMessage) { }

    func channel(_ channel: BaseChannel, didUpdate message: BaseMessage) { }

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

    func channel(_ channel: BaseChannel, didReceiveMention message: BaseMessage) { }

    func channelWasChanged(_ channel: BaseChannel) { }

    func channelWasDeleted(_ channelURL: String, channelType: ChannelType) { }

    func channelWasFrozen(_ channel: BaseChannel) { }

    func channelWasUnfrozen(_ channel: BaseChannel) { }

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

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

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

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

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

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

    func channelWasHidden(_ channel: GroupChannel) { }

    func channel(_ channel: GroupChannel, didReceiveInvitation invitees: [User]?, inviter: User?) { }

    func channel(_ channel: GroupChannel, didDeclineInvitation invitee: User?, inviter: User?) { }

    func channel(_ channel: GroupChannel, userDidJoin user: User) { }

    func channel(_ channel: GroupChannel, userDidLeave user: User) { }

    func channelDidUpdateDeliveryStatus(_ channel: GroupChannel) { }

    func channelDidUpdateReadStatus(_ channel: GroupChannel) { }

    func channelDidUpdateTypingStatus(_ channel: GroupChannel) { }

    func channel(_ channel: BaseChannel, userWasMuted user: RestrictedUser) { }

    func channel(_ channel: BaseChannel, userWasUnmuted user: User) { }

    func channel(_ channel: BaseChannel, userWasBanned user: RestrictedUser) { }

    func channel(_ channel: BaseChannel, userWasUnbanned user: User) { }

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

Remove a channel event delegate

The following code shows how to remove the channel delegate.

SendbirdChat.removeChannelDelegate(forIdentifier: UNIQUE_DELEGATE_ID)