Channel Groups API for Swift Native SDK
Channel groups allow PubNub developers to bundle thousands of channels into a group that can be identified by a name. These channel groups can then be subscribed to, receiving data from the many back-end channels the channel group contains.
Channel group operations
You can't publish to a channel group. You can only subscribe to it. To publish within the channel group, you need to publish to each channel individually.
Add channels to a channel group
Requires Stream Controller add-on
This method requires that the Stream Controller add-on is enabled for your key in the PubNub Admin Portal. Read the support page on enabling add-on features on your keys.
This function adds channels to a channel group.
Method(s)
Adding Channels is accomplished by using the following method(s) in the Swift SDK:
Maximum number of channels
You can add up to 200 channels to a channel group per API call.
1func add(
2 channels: [String],
3 to group: String,
4 custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
5 completion: `((Result<[String: [String]], Error>) -> Void)?`
6)
| Parameter | Description |
|---|---|
channels *Type: [String] Default: n/a | List of channels to add to the group. |
to *Type: String Default: n/a | The Channel Group to add the list of channels to. |
customDefault: PubNub.RequestConfiguration() | An object that allows for per-request customization of PubNub configuration or network session. For more information, refer to the Request Configuration section. |
completionType: ((Result<(group: String, channels: [String]), Error>) -> Void)?Default: nil | The async Result of the method call. |
Completion handler result
Success
A Tuple containing the channel-group and the Array of channels added.
Failure
An Error describing the failure.
Sample code
Add channels
Reference code
1
List channels in a channel group
Requires Stream Controller add-on
This method requires that the Stream Controller add-on is enabled for your key in the Admin Portal. Read the support page on enabling add-on features on your keys.
This function lists all channels in a channel group.
Method(s)
Listing Channels is accomplished by using the following method(s) in the Swift SDK:
1func listChannels(
2 for group: String,
3 custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
4 completion: ((Result<(group: String, channels: [String]), Error>) -> Void)?
5)
| Parameter | Description |
|---|---|
for *Type: String Default: n/a | The channel group to list channels on. |
customDefault: PubNub.RequestConfiguration() | An object that allows for per-request customization of PubNub configuration or network session. For more information, refer to the Request Configuration section. |
completionType: ((Result<(group: String, channels: [String]), Error>) -> Void)?Default: nil | The async Result of the method call. |
Completion handler result
Success
A Tuple containing the channel-group and the Array of its channels.
Failure
An Error describing the failure.
Sample code
List channels
1
Remove channels from a channel group
Requires Stream Controller add-on
This method requires that the Stream Controller add-on is enabled for your key in the Admin Portal. Read the support page on enabling add-on features on your keys.
This function removes channels from the channel group.
Method(s)
Removing Channels is accomplished by using the following method(s) in the Swift SDK:
1func remove(
2 channels: [String],
3 from group: String,
4 custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
5 completion: ((Result<(group: String, channels: [String]), Error>) -> Void)?
6)
| Parameter | Description |
|---|---|
channels *Type: [String] Default: n/a | The list of channels to remove from the channel group. |
from *Type: String Default: n/a | The channel group to remove channels from. |
customType: PubNub.RequestConfigurationDefault: PubNub.RequestConfiguration() | An object that allows for per-request customization of PubNub Configuration or Network Session. |
completionType: ((Result<(group: String, channels: [String]), Error>) -> Void)?Default: nil | The async Result of the method call. |
Completion handler result
Success
A Tuple containing the channel-group and the Array of channels removed.
Failure
An Error describing the failure.
Sample code
Remove channels
1
List channel groups
Requires Stream Controller add-on
This method requires that the Stream Controller add-on is enabled for your key in the Admin Portal. Read the support page on enabling add-on features on your keys.
This function lists all the channel groups.
Method(s)
Listing Channel Groups is accomplished by using the following method(s) in the Swift SDK:
1func listChannelGroups(
2 custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
3 completion: `((Result<[String], Error>) -> Void)?`
4)
| Parameter | Description |
|---|---|
customDefault: PubNub.RequestConfiguration() | An object that allows for per-request customization of PubNub configuration or network session. For more information, refer to the Request Configuration section. |
completionType: ((Result<[String], Error>) -> Void)?Default: nil | The async Result of the method call. |
Completion handler result
Success
List of all channel-groups.
Failure
An Error describing the failure.
Sample code
List channel groups
1
Delete a channel group
Requires Stream Controller add-on
This method requires that the Stream Controller add-on is enabled for your key in the Admin Portal. Read the support page on enabling add-on features on your keys.
This function removes the channel group.
Method(s)
Deleting Channel Group is accomplished by using the following method(s) in the Swift SDK:
1func remove(
2 channelGroup: String,
3 custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
4 completion: ((Result<String, Error>) -> Void)?
5)
| Parameter | Description |
|---|---|
channelGroup *Type: String Default: n/a | The channel group to delete. |
customDefault: PubNub.RequestConfiguration() | An object that allows for per-request customization of PubNub configuration or network session. For more information, refer to the Request Configuration section. |
completionType: ((Result<String, Error>) -> Void)?Default: nil | The async Result of the method call. |
Completion handler result
Success
The channel-group that was removed.
Failure
An Error describing the failure.
Sample code
Delete channel group
1