/ SDKs / iOS
SDKs
Chat SDKs iOS v4
Chat SDKs iOS
Chat SDKs
iOS
Version 4

Receive messages in an open channel

Copy link

The current user can receive messages sent by other participants through the channel(_:didReceive:) method in channel delegate. A BaseMessage object for each received message is one of the following message types.

Message typeClassDescription

Text

UserMessage

A text message sent by a user

File

FileMessage

A binary file message sent by a user

Admin

AdminMessage

A text message sent by an admin through the Chat API

To register multiple concurrent handlers, pass a UNIQUE_DELEGATE_ID argument as a unique identifier into the SendbirdChat.add() method.

class OpenChannelChattingViewController: UIViewController, OpenChannelDelegate {
    func initViewController() {
        SendbirdChat.add(self, identifier: UNIQUE_DELEGATE_ID)
    }

    func channel(_ sender: BaseChannel, didReceive message: BaseMessage) {
        // You can customize how to display the different types of messages
        // with the result object in the message parameter.
        if message is UserMessage {

        }
        else if message is FileMessage {

        }
        else if message is AdminMessage {

        }
    }
}

If the UI is no longer valid, remove the channel delegate using the following code.

SendbirdChat.removeChannelDelegate(forIdentifier: UNIQUE_DELEGATE_ID)

Event delegate for message threading

Copy link

Once a reply is created or deleted from a thread, the channel(_:didUpdateThreadInfo:) event delegate method is invoked. The method returns a ThreadInfoUpdateEvent object that has the latest information about the thread. This object needs to be applied to the parent message object.

Note: Like other messages, when a reply is created in a channel, the channel(_:didReceive:) method of the channel event delegate in client apps will be called.

func channel(_ channel: BaseChannel, didUpdateThreadInfo threadInfoUpdateEvent: ThreadInfoUpdateEvent) {
    // Look for a message that has threadInfoUpdateEvent.targetMessageId
    // Apply the event to the message.
    message.apply(threadInfoUpdateEvent)
}

List of parameters

Copy link
Parameter nameTypeDescription

channel

BaseChannel

Specifies the channel that has the message thread.

threadInfoUpdateEvent

ThreadInfoUpdateEvent

Specifies a ThreadInfoUpdateEvent object that has the latest information about the thread.