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

Retrieve a list of channels

You can retrieve a list of OpenChannel objects using the loadNextPage(completionHandler:) method of an OpenChannelListQuery instance and a list of GroupChannel objects using the loadNextPage(completionHandler:) method of a GroupChannelListQuery instance.

Creating a GroupChannelListQuery instance returns a list of the user's private group channels. A different approach is needed to retrieve a list of public group channels and Supergroup channels as described later in this page.

When creating a GroupChannelListQuery instance, the includeEmptyChannel option of GroupChannelListQueryParams is set to true by default to allow users to view channels that may be empty because the chat history option is turned off and prevents new members from seeing previous conversations. You can determine whether to turn on the chat history option on Sendbird Dashboard under Settings > Chat > Channels > Group channels.

Note: You can also search for specific open channels and group channels with keywords and filters.

Open channel

class CustomViewController: ViewController {
    var query: GroupChannelListQuery?

    func createQuery() {
        self.query = GroupChannel.createMyGroupChannelListQuery { params in
            // The `params` object is the `GroupChannelListQueryParams` class.
            params.includeEmptyChannel = true
            params.memberStateFilter = .joinedOnly   // Acceptable values are .all, .joinedOnly, .invitedOnly, .invitedByFriend, and .invitedByNonFriend.
            params.order = .latestLastMessage    // Acceptable values are .chronological, .latestLastMessage, .channelNameAlphabetical, and .channelMetaDataValueAlphabetical.
            params.limit = 15
        }
    }

    func loadNextPage() {
        self.query?.loadNextPage { channels, error in
            guard error == nil else {
                // Handle error.
                return
            }

            // A list of matching group channels is successfully retrieved.
            // Through the channels parameter of the callback method,
            // you can access the data of each group channel from the result list
            // that the Sendbird server has passed to the callback method.
        }
    }
}

Group channel

class CustomViewController: ViewController {
    var query: OpenChannelListQuery?

    func createQuery() {
        self.query = OpenChannel.createOpenChannelListQuery()
    }

    func loadNextPage() {
        self.query?.loadNextPage { channels, error in
            guard error == nil else {
                // Handle error.
                return
            }

            // A list of open channels is successfully retrieved.
            // Through the openChannels parameter of the callback method,
            // you can access the data of each open channel from the result list
            // that the Sendbird server has passed to the callback method.
        }
    }
}

Public group channels

You can retrieve a list of the current user's public group channels using the loadNextPage(completionHandler:) method of a PublicGroupChannelListQuery instance.

class CustomViewController: ViewController {
    var query: PublicGroupChannelListQuery?

    func createQuery() {
        self.query = GroupChannel.createPublicGroupChannelListQuery { params in
            // The params object is created from the PublicGroupChannelListQueryParams class.
            params.includeEmptyChannel = true
            params.publicMembershipFilter = .joined  // Acceptable values are .all, .joined
            params.order = .channelNameAlphabetical  // Acceptable values are .chronological, .channelNameAlphabetical, .channelMetaDataValueAlphabetical
            params.limit = 15
        }
    }

    func loadNextPage() {
        self.query?.loadNextPage { channels, error in
            guard error == nil else {
                // Handle error.
                return
            }

            // A list of public group channels is retrieved according to the params.
            // Through the channels parameter of the callback method,
            // you can access the data of each group channel from the result list
            // that the Sendbird server has passed to the callback method.
        }
    }
}

Supergroup channels

Like how you search group channels using filters, you can retrieve a list of Supergroup channels through the GroupChannelListQuery's superChannelFilter property. The query params is passed to the createMyGroupChannelListQuery(paramsBuilder:) method of the GroupChannel class.

When the channels are returned, you can tell which channel is a Supergroup channel by looking at the isSuper property. If the property has a value of true, the channel is a Supergroup channel.

class CustomViewController: ViewController {
    var query: GroupChannelListQuery?

    func createQuery() {
        self.query = GroupChannel.createMyGroupChannelListQuery { params in
            // The params object is created from the GroupChannelListQueryParams class.
            params.superChannelFilter = .super
        }
    }

    func loadNextPage() {
        self.query?.loadNextPage { groupChannels, error in
            guard error == nil else {
                // Handle error.
                return
            }

            // A list of Supergroup channels is successfully retrieved.
            // Through the groupChannels parameter of the callback method,
            // you can access the data of each group channel from the result list
            // that the Sendbird server has passed to the callback method.
        }
    }
}