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. See Enable the features your app calls.
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)
channelsrequired#- List of
channelsto add to the group. torequired#- The Channel Group to add the list of channels to.
custom#- An object that allows for per-request customization of PubNub configuration or network session. For more information, refer to the Request Configuration section.
completion#- The async
Resultof 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
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. See Enable the features your app calls.
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)
forrequired#- The channel group to list channels on.
custom#- An object that allows for per-request customization of PubNub configuration or network session. For more information, refer to the Request Configuration section.
completion#- The async
Resultof 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. See Enable the features your app calls.
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)
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. See Enable the features your app calls.
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)
custom#- An object that allows for per-request customization of PubNub configuration or network session. For more information, refer to the Request Configuration section.
completion#- The async
Resultof 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. See Enable the features your app calls.
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)
channelGrouprequired#- The channel group to delete.
custom#- An object that allows for per-request customization of PubNub configuration or network session. For more information, refer to the Request Configuration section.
completion#- The async
Resultof 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