Channel Groups API for PubNub Cocoa Swift SDK

This SDK has been replaced by a new PubNub Swift SDK written purely in Swift. Check it out here

Channel Groups allows PubNub developers to bundle thousands of channels into a group that can be identified by name. These Channel Groups can then be subscribed to, receiving data from the many back-end channels the channel group contains.

Learn more about our Channel Groups here.

Channel Group operations

You can't publish to a Channel Group. You can only subscribe to it. To publish within Channel Group, you need to publish to each channel individually.

Adding Channels

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.

Description

This function adds a channel to a channel group.

Method(s)

Adding Channels is accomplished by using the following method(s) in the Swift SDK:

open func addChannels(_ channels: [String], toGroup group: String, withCompletion closure: PubNub.PNChannelGroupChangeCompletionBlock? = nil)
ParameterTypeRequiredDescription
channels[String]YesList of channel names which should be added to the group.
groupStringYesName of the group into which channels should be added.
closurePNChannelGroupChangeCompletionBlockNoChannel(s) addition completion closure, has one argument - request processing status to report whether data push was successful or not (errorData contains error information in case of failure).

Basic Usage

Adding Channels

let channelGroup = "family"
self.client.addChannels(["wife"], toGroup: channelGroup, withCompletion: { (status) in

if !status.isError {

// Handle successful channels list modification for group.
}
else {

/**
Handle channels list modification for group error. Check 'category' property
to find out possible reason because of which request did fail.
Review 'errorData' property (which has PNErrorData data type) of status
object to get additional information about issue.

Request can be resent using: status.retry()
show all 18 lines

Response

Response objects which is returned by client when Add Channels to Group API is used:

open class PNAcknowledgmentStatus : PNErrorStatus {

}

Listing Channels

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.

Description

This function lists all the channels of the channel group.

Method(s)

Listing Channels is accomplished by using the following method(s) in the Swift SDK:

open func channelsForGroup(_ group: String, withCompletion closure: PubNub.PNGroupChannelsAuditCompletionBlock)
ParameterTypeRequiredDescription
groupStringYesChannel Group to list the channel(s) of.
closurePNGroupChannelsAuditCompletionBlockYesThe completion closure which will be called when the processing is complete, has two arguments: result - in case of successful processing (data field will contain results of channel groups audit operation); status - in case of error while processing (errorDatacontains error information).

Basic Usage

Listing Channels

let channelGroup = "family"
self.client.channelsForGroup(channelGroup, withCompletion: { (result, status) in

if status == nil {

// Handle downloaded list of chanels using: result.data.channels
}
else {

/**
Handle channels for group audition error. Check 'category' property
to find out possible reason because of which request did fail.
Review 'errorData' property (which has PNErrorData data type) of status
object to get additional information about issue.

Request can be resent using: status.retry()
show all 18 lines

Response

Response objects which is returned by client when Add Channels to Group API is used:

open class PNChannelGroupChannelsData : PNServiceData {

// Registered channels within channel group.
open var channels: [String] { get }
}

open class PNChannelGroupChannelsResult : PNResult {

// Stores reference on channel group's channels list audit request processing information.
open var data: PNChannelGroupChannelsData { get }
}

Removing Channels

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.

Description

This function removes the channels from the channel group.

Method(s)

Removing Channels is accomplished by using the following method(s) in the Swift SDK:

open func removeChannels(_ channels: [String], fromGroup group: String, withCompletion closure: PubNub.PNChannelGroupChangeCompletionBlock? = nil)
ParameterTypeRequiredDescription
channels[String]YesList of channel names which should be removed from group. If empty list passed whole channel group will be removed.
groupStringYesChannel group from which channels should be removed.
closurePNChannelGroupChangeCompletionBlockNoThe completion closure which will be called when the processing is complete, has one argument: request processing status - in case of error while processing (errorDatacontains error information).

Basic Usage

Removing channels :

let channelGroup = "family"
self.client.removeChannels(["son"], fromGroup: channelGroup, withCompletion: { (status) in

if !status.isError {

// Handle successful channels list modification for group.
}
else {

/**
Handle channels list modification for group error. Check 'category' property
to find out possible reason because of which request did fail.
Review 'errorData' property (which has PNErrorData data type) of status
object to get additional information about issue.

Request can be resent using: status.retry();
show all 18 lines

Response

Response objects which is returned by client when Remove Channels to Group API is used:

open class PNAcknowledgmentStatus : PNErrorStatus {

}

Deleting 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.

Description

This function removes the channel group.

Method(s)

Deleting Channel Group is accomplished by using the following method(s) in the Swift SDK:

open func removeChannelsFromGroup(_ group: String, withCompletion closure: PubNub.PNChannelGroupChangeCompletionBlock? = nil)
ParameterTypeRequiredDescription
groupStringYesName of the group from which all channels should be removed.
closurePNChannelGroupChangeCompletionBlockNoThe completion closure which will be called when the processing is complete, has one argument: request processing status - in case of error while processing (errorDatacontains error information).

Basic Usage

Deleting Channel Group :

let channelGroup = "family"
self.client.removeChannelsFromGroup(channelGroup, withCompletion: { (status) in

if !status.isError {

// Handle successful channel group removal.
}
else {

/**
Handle channel group removal error. Check 'category' property
to find out possible reason because of which request did fail.
Review 'errorData' property (which has PNErrorData data type) of status
object to get additional information about issue.

Request can be resent using: status.retry();
show all 18 lines

Response

Response objects which is returned by client when Remove Channel Group API is used:

open class PNAcknowledgmentStatus : PNErrorStatus {

}