List all channels
Get a paginated list of all channels with getChannels(). Custom channel metadata is included by default.
Requires App Context
Enable App Context for your keyset in the Admin Portal.
To list channels a user belongs to, use getMemberships() instead.
Method signature
This method takes the following parameters:
1chat.getChannels(
2 filter: String? = nil,
3 sort: [PubNub.ObjectSortField] = [],
4 limit: Int? = nil,
5 page: PubNubHashedPage? = nil,
6) async throws -> (channels: [ChannelImpl], page: PubNubHashedPage?)
Input
| Parameter | Description |
|---|---|
filterType: StringDefault: n/a | Expression used to filter the results. Returns only these channels whose properties satisfy the given expression are returned. The filter language is defined here. |
sortType: [PubNub.ObjectSortField]Default: [] | A collection to specify the sort order. Available options are id, name, and updated. Use asc or desc to specify the sorting direction, or specify null to take the default sorting direction (ascending). For example: {name: "asc"}. Unless specified otherwise, the items are sorted by the last updated date. Defaults to an empty list. |
limitType: IntDefault: nil | Number of objects to return in response. The default (and maximum) value is 100. |
pageType: PubNubHashedPage?Default: nil | Object used for pagination to define which previous or next result page you want to fetch. |
Output
| Parameter | Description |
|---|---|
(channels: [ChannelImpl], page: PubNubHashedPage?) | A tuple containing a set of channels and pagination information indicating the start, end, and total count of the members. |
Sample code
Sample code
The code samples in Swift Chat SDK focus on asynchronous code execution.
You can also write synchronous code as the parameters are shared between the async and sync methods but we don't provide usage examples of such.
Fetch all existing channel IDs.
1
Other examples
Pagination
Get the first 25 channels and then fetch results from the next page using a page previously returned from the PubNub server.
1
Archived channels
Get all archived channels. This request will return all channels removed with the soft option set to true, whose data is still stored in the App Context storage.
1