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

Receive messages in a group channel

Messages sent from other members can be received through the channel(_:didReceive:) method in channel delegate. A BaseMessage object for each received message is one of the following message types.

Message typeDescription

UserMessage

A text message sent by a user

FileMessage

A binary file message sent by a user

AdminMessage

A text message sent by an admin through the Platform API

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

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

    func channel(_ channel: 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 {

        }
    }
}

When the UI isn't valid anymore, remove the channel event handler.

SendbirdChat.removeChannelDelegate(forIdentifier: UNIQUE_DELEGATE_ID)

Event delegate for message threading

When a reply is created in a channel, the channel(_:didReceive:) method of the channel event delegate in client apps is called. 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.

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

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.


Receive an update event for delivery receipts

When a message is delivered to a group channel member who is online at the time, it is automatically marked as delivered and other members who are online are also notified of the successful message delivery through the channelDidUpdateDeliveryStatus(_:) method of GroupChannelDelegate. However, when a message is delivered to an offline member as a push notification, the message can be marked as delivered through the markAsDelivered(remoteNotificationPayload:completionHandler:) method of SendbirdChat, and other members who are online are notified of the successful message delivery through the channelDidUpdateDeliveryStatus(_:) method of GroupChannelDelegate.

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

    func channelDidUpdateDeliveryStatus(_ channel: GroupChannel) {

    }
}