Channel Groups API for Cocoa Objective-C 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)

Use the following method in the Cocoa SDK:

- (void)addChannels:(NSArray<NSString *> *)channels
toGroup:(NSString *)group
withCompletion:(nullable PNChannelGroupChangeCompletionBlock)block;
* required
ParameterDescription
channels *
Type: NSArray
The channels to add to the channel group.
group *
Type: NSString
The channel group to add the channels to.
block
Type: PNChannelGroupChangeCompletionBlock
Channels addition process completion block which pass only one argument - request processing status to report about how data pushing was successful or not.

Sample code

Add channels

NSString *channelGroup = @"family";
[self.client addChannels: @[@"wife"] toGroup:channelGroup
withCompletion:^(PNAcknowledgmentStatus *status) {

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.

show all 19 lines

Response

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

@interface PNAcknowledgmentStatus : PNErrorStatus

@end

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)

Use the following method in the Cocoa SDK:

- (void)channelsForGroup:(NSString *)group
withCompletion:(PNGroupChannelsAuditCompletionBlock)block;
* required
ParameterDescription
group *
Type: NSString
The channel group for which to list channels.
block *
Type: PNClientChannelsForGroupRequestHandlingBlock
Channels audition process completion block which pass two arguments: result - in case of successful request processing data field will contain results of channel groups channels audition operation; status - in case if error occurred during request processing.

Sample code

List channels

NSString *channelGroup = @"family";
[self.client channelsForGroup:channelGroup withCompletion:^(PNChannelGroupChannelsResult *result,
PNErrorStatus *status) {

if (!status) {

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

show all 19 lines

Response

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

@interface PNChannelGroupChannelsData : PNServiceData

// Registered channels within channel group.
@property (nonatomic, readonly, strong) NSArray<NSString *> *channels;

@end

@interface PNChannelGroupChannelsResult : PNResult

// Stores reference on channel group's channels list audit request processing information.
@property (nonatomic, nonnull, readonly, strong) PNChannelGroupChannelsData *data;

@end

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 a channel group.

Method(s)

Use the following method in the Cocoa SDK:

- (void)removeChannels:(NSArray<NSString *> *)channels
fromGroup:(NSString *)group
withCompletion:(nullable PNChannelGroupChangeCompletionBlock)block;
* required
ParameterDescription
channels *
Type: NSArray
The channels to remove from the channel group.
group *
Type: NSString
The channel group from which to remove the channels.
block
Type: PNChannelGroupChangeCompletionBlock
Channels removal process completion block which pass only one argument - request processing status to report about how data pushing was successful or not.

Sample code

Remove channels

NSString *channelGroup = @"family";
[self.client removeChannels:@[@"son"] fromGroup:channelGroup
withCompletion:^(PNAcknowledgmentStatus *status) {

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.

show all 19 lines

Response

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

@interface PNAcknowledgmentStatus : PNErrorStatus

@end

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 deletes a channel group.

Method(s)

Use the following method in the Cocoa SDK:

- (void)removeChannelsFromGroup:(NSString *)group 
withCompletion:(nullable PNChannelGroupChangeCompletionBlock)block;
* required
ParameterDescription
group *
Type: NSString
The channel group to delete.
block
Type: PNChannelGroupChangeCompletionBlock
Channel group removal process completion block which pass only one argument - request processing status to report about how data pushing was successful or not.

Sample code

Deleting Channel Group:

NSString *channelGroup = @"family";
[self.client removeChannelsFromGroup:channelGroup withCompletion:^(PNAcknowledgmentStatus *status) {

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:

@interface PNAcknowledgmentStatus : PNErrorStatus

@end
Last updated on