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.

Search open channels by name, URL, or custom type

You can search for specific open channels by adding a keyword to an OpenChannelListQueryParams when creating an OpenChannelListQuery instance. There are two types of keywords, which are name and URL.

The code sample below shows the query instance with channelNameFilter, which returns a list of open channels that partially match the specified keyword in the channel names.

class CustomViewController: ViewController {
    var query: OpenChannelListQuery?
    
    func createQuery() {
        self.query = OpenChannel.createOpenChannelListQuery { params in
            // The params object is the OpenChannelListQueryParams class.
            params.channelNameFilter = "Sendbird"
        }
    }
    
    func loadNextPage() {
        self.query?.loadNextPage { openChannels, error in
            guard error == nil else {
                // Handle error.
                return
            }

            // Through the openChannels parameter of the callback method,
            // which the Sendbird server has passed a result list to,
            // a list of open channels whose name partially matches
            // with the filter value is returned.
        }
    }
}

The following shows the query instance with channelURLFilter, which returns a list of open channels that partially match the specified keyword in the channel URLs.

class CustomViewController: ViewController {
    var query: OpenChannelListQuery?
    
    func createQuery() {
        self.query = OpenChannel.createOpenChannelListQuery { params in
            // The params object is the OpenChannelListQueryParams class.
            params.channelURLFilter = "seminar"
        }
    }
    
    func loadNextPage() {
        self.query?.loadNextPage { openChannels, error in
            guard error == nil else {
                // Handle error.
                return
            }

            // Through the openChannels parameter of the callback method,
            // which the Sendbird server has passed a result list to,
            // a list of open channels whose URL partially matches
            // with the filter value is returned.
        }
    }
}

You can also search for open channels with a specific custom type by setting customTypeFilter as in the code below.

class CustomViewController: ViewController {
    var query: OpenChannelListQuery?
    
    func createQuery() {
        self.query = OpenChannel.createOpenChannelListQuery { params in
            // The params object is the OpenChannelListQueryParams class.
            params.customTypeFilter = "movie"
        }
    }
    
    func loadNextPage() {
        self.query?.loadNextPage { openChannels, error in
            guard error == nil else {
                // Handle error.
                return
            }

            // Through the openChannels parameter of the callback method,
            // which the Sendbird server has passed a result list to,
            // a list of open channels whose custom type matches
            // with the filter value is returned.
        }
    }
}