App Context API for Objective- SDK
This page describes App Context (formerly Objects v2). To upgrade from Objects v1, refer to the migration guide.
App Context provides easy-to-use, serverless storage for user and channel data you need to build innovative, reliable, scalable applications. Use App Context to store metadata about your application users and channels, and their membership associations, without running your own databases.
PubNub also triggers events when object data changes: set, update, or removal. Setting the same data again doesn't trigger an event. Clients can receive these events in real time and update their front-end application accordingly.
User
Get metadata for all users
Returns a paginated list of UUID Metadata objects, optionally including the custom data object for each.
Method(s)
To Get All UUID Metadata you can use the following method(s) in the Objective-C SDK:
1- (void)allUUIDMetadataWithRequest:(PNFetchAllUUIDMetadataRequest *)request 
2                        completion:(PNFetchAllUUIDMetadataCompletionBlock)block;
| Parameter | Description | 
|---|---|
| request* | Request object for fetching all UUID metadata. | 
| block*Type: PNFetchAllUUIDMetadataCompletionBlock | Completion block. | 
PNFetchAllUUIDMetadataRequest
| Parameter | Description | 
|---|---|
| sortType: NSArray <NSString *> | Sort by id, name, updated with asc/desc for sort direction (for example, {name: 'asc'}). | 
| includeFieldsType: PNUUIDFields | Bitfield of response fields. Supported: PNUUIDTotalCountField(total count),PNUUIDCustomField(UUID custom),PNUUIDStatusField(UUID status),PNUUIDTypeField(UUID type). Default isPNUUIDTotalCountField(set 0 to reset). | 
| filterType: NSString | Filter expression. Only matching objects are returned. See filtering. | 
| startType: NSString | Cursor-based pagination. | 
| endType: NSString | Cursor-based pagination. Ignored if the startparameter is supplied. | 
| limitType: NSUInteger | Number of objects to return. Default/Max: 100. | 
Sample code
1#import <Foundation/Foundation.h>
2#import <PubNub/PubNub.h>
3
4// Basic configuration
5PNConfiguration *config = [PNConfiguration configurationWithPublishKey:@"demo"
6                                                          subscribeKey:@"demo"
7                                                                userID:@"metadataUser"];
8
9// Create a PubNub client instance
10PubNub *client = [PubNub clientWithConfiguration:config];
11
12// Example 1: Basic UUID metadata fetch
13NSLog(@"Fetching all UUID metadata...");
14
15// Create a basic request
Response
Response returned by the client for fetch all UUID metadata:
1@interface PNFetchAllUUIDMetadataData : PNServiceData
2
3// List of UUID metadata objects created for current subscribe key.
4@property (nonatomic, readonly, strong) NSArray<PNUUIDMetadata *> *metadata;
5
6// Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
7@property (nonatomic, nullable, readonly, strong) NSString *next;
8
9// Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data.
10@property (nonatomic, nullable, readonly, strong) NSString *prev;
11
12/**
13 * Total number of objects created for current subscribe key.
14 *
15 * Value will be 0 in case if PNUUIDTotalCountField not added to 'includeFields'
Error response which is used in case of App Context API call failure:
1@interface PNErrorData : PNServiceData
2
3// Stringified error information.
4@property (nonatomic, readonly, strong) NSString *information;
5
6@end
7
8@interface PNErrorStatus : PNStatus
9
10// Whether status object represent error or not.
11@property (nonatomic, readonly, assign, getter = isError) BOOL error;
12
13// Additional information related to error status object.
14@property (nonatomic, readonly, strong) PNErrorData *errorData;
15
Get metadata for all users (builder pattern)
Method(s)
1objects()
2    .allUUIDMetadata()
3    .includeFields(PNUUIDFields)
4    .includeCount(BOOL)
5    .filter(NSString *)
6    .sort(NSArray<NSString *> *)
7    .limit(NSUInteger)
8    .start(NSString *)
9    .end(NSString *)
10    .performWithCompletion(PNFetchAllUUIDMetadataCompletionBlock);
| Parameter | Description | 
|---|---|
| includeFieldsType: PNUUIDFields | Bitfield of response fields. Supported: PNUUIDTotalCountField(number of UUID metadata records),PNUUIDCustomField(custom set during UUID metadata set),PNUUIDStatusField(status set during UUID metadata set),PNUUIDTypeField(type set during UUID metadata set). Default isPNUUIDTotalCountField(set 0 to reset). | 
| includeCountType: BOOL | Whether to include the total count in the paginated response. Default: YES | 
| filterType: NSString | Filter expression. Only matching objects are returned. See filtering. | 
| sortType: NSArray | Sort by id, name, updated with asc/desc for sort direction (for example, {name: 'asc'}). | 
| limitType: NSUInteger | Number of objects to return. Default/Max: 100. | 
| startType: NSString | Cursor-based pagination. | 
| endType: NSString | Cursor-based pagination. Ignored if the startparameter is supplied. | 
| block*Type: PNFetchAllUUIDMetadataCompletionBlock | Associated metadata fetchcompletion handler block. | 
Note
This method uses the builder pattern, you can remove the arguments which are optional.
Sample code
1self.client.objects().allUUIDMetadata()
2    .start(@"<next from previous request>")
3    .includeFields(PNUUIDCustomField)
4    .includeCount(YES)
5    .limit(40)
6    .performWithCompletion(^(PNFetchAllUUIDMetadataResult *result, PNErrorStatus *status) {
7        if (!status.isError) {
8            /**
9             * UUID metadata successfully fetched.
10             * Result object has following information:
11             *   result.data.metadata - List of fetched UUID metadata.
12             *   result.data.next - Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
13             *   result.data.prev - Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data.
14             *   result.data.totalCount - Total number of created UUID metadata.
15             */
Response
Response returned by the client for fetch all UUID metadata:
1@interface PNFetchAllUUIDMetadataData : PNServiceData
2
3// List of UUID metadata objects created for current subscribe key.
4@property (nonatomic, readonly, strong) NSArray<PNUUIDMetadata *> *metadata;
5
6// Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
7@property (nonatomic, nullable, readonly, strong) NSString *next;
8
9// Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data.
10@property (nonatomic, nullable, readonly, strong) NSString *prev;
11
12/**
13 * Total number of objects created for current subscribe key.
14 *
15 * Value will be 0 in case if PNUUIDTotalCountField not added to 'includeFields'
Error response which is used in case of App Context API call failure:
1@interface PNErrorData : PNServiceData
2
3// Stringified error information.
4@property (nonatomic, readonly, strong) NSString *information;
5
6@end
7
8@interface PNErrorStatus : PNStatus
9
10// Whether status object represent error or not.
11@property (nonatomic, readonly, assign, getter = isError) BOOL error;
12
13// Additional information related to error status object.
14@property (nonatomic, readonly, strong) PNErrorData *errorData;
15
Get user metadata
Returns metadata for the specified UUID, optionally including the custom data object for each.
Method(s)
To Get UUID Metadata you can use the following method(s) in the Objective-C SDK:
1- (void)uuidMetadataWithRequest:(PNFetchUUIDMetadataRequest *)request 
2                     completion:(PNFetchUUIDMetadataCompletionBlock)block;
| Parameter | Description | 
|---|---|
| request* | Request object for fetching UUID metadata. | 
| block*Type: PNFetchUUIDMetadataCompletionBlock | Completion block. | 
PNFetchUUIDMetadataRequest
| Parameter | Description | 
|---|---|
| includeFieldsType: PNUUIDFields | Bitfield of response fields. Supported: PNUUIDCustomField(custom set during UUID metadata set),PNUUIDStatusField(status set during UUID metadata set),PNUUIDTypeField(type set during UUID metadata set). | 
| uuidType: NSString | Create and configure fetch UUIDmetadata request.uuid- Identifier for metadata should be fetched. Will be set to current PubNub configuration uuid if nil is set. | 
Sample code
1PNFetchUUIDMetadataRequest *request = [PNFetchUUIDMetadataRequest requestWithUUID:@"uuid"];
2// Add this request option, if returned metadata model should have value which has been set to
3// 'custom' property.
4request.includeFields = PNUUIDCustomField;
5
6[self.client uuidMetadataWithRequest:request
7                          completion:^(PNFetchUUIDMetadataResult *result, PNErrorStatus *status) {
8
9    if (!status.isError) {
10        /**
11         * UUID metadata successfully fetched.
12         * Fetched UUID metadata information available here: result.data.metadata
13         */
14    } else {
15        /**
Response
Response returned by the client for fetch UUID metadata:
1@interface PNFetchUUIDMetadataData : PNServiceData
2
3// Requested UUID metadata object.
4@property (nonatomic, nullable, readonly, strong) PNUUIDMetadata *metadata;
5
6@end
7
8@interface PNFetchUUIDMetadataResult : PNResult
9
10// Fetch UUID metadata request processed information.
11@property (nonatomic, readonly, strong) PNFetchUUIDMetadataData *data;
12
13@end
Error response which is used in case of App Context API call failure:
1@interface PNErrorData : PNServiceData
2
3// Stringified error information.
4@property (nonatomic, readonly, strong) NSString *information;
5
6@end
7
8@interface PNErrorStatus : PNStatus
9
10// Whether status object represent error or not.
11@property (nonatomic, readonly, assign, getter = isError) BOOL error;
12
13// Additional information related to error status object.
14@property (nonatomic, readonly, strong) PNErrorData *errorData;
15
Get user metadata (builder pattern)
Method(s)
1objects()
2    .uuidMetadata()
3    .uuid(NSString *)
4    .includeFields(PNUUIDFields)
5    .performWithCompletion(PNFetchUUIDMetadataCompletionBlock);
| Parameter | Description | 
|---|---|
| uuidType: NSString | Identifier for which associated metadatashould be fetched. Default: configured PubNub clientuuid | 
| includeFieldsType: PNUUIDFields | Bitfield of response fields. Supported: PNUUIDCustomField(custom set during UUID metadata set),PNUUIDStatusField(status set during UUID metadata set),PNUUIDTypeField(type set during UUID metadata set). | 
| block*Type: PNFetchUUIDMetadataCompletionBlock | Fetch UUID metadatarequest completionblock. | 
Note
This method uses the builder pattern, you can remove the arguments which are optional.
Sample code
1self.client.objects().uuidMetadata()
2    .uuid(@"uuid")
3    .includeFields(PNUUIDCustomField)
4    .performWithCompletion(^(PNFetchUUIDMetadataResult *result, PNErrorStatus *status) {
5      if (!status.isError) {
6          /**
7           * UUID metadata successfully fetched.
8           * Fetched UUID metadata information available here: result.data.metadata
9           */
10      } else {
11          /**
12           * Handle UUID metadata fetch error. Check 'category' property to find out possible issue
13           * because of which request did fail.
14           *
15           * Request can be resent using: [status retry]
Response
Response returned by the client for fetch UUID metadata:
1@interface PNFetchUUIDMetadataData : PNServiceData
2
3// Requested UUID metadata object.
4@property (nonatomic, nullable, readonly, strong) PNUUIDMetadata *metadata;
5
6@end
7
8@interface PNFetchUUIDMetadataResult : PNResult
9
10// Fetch UUID metadata request processed information.
11@property (nonatomic, readonly, strong) PNFetchUUIDMetadataData *data;
12
13@end
Error response which is used in case of App Context API call failure:
1@interface PNErrorData : PNServiceData
2
3// Stringified error information.
4@property (nonatomic, readonly, strong) NSString *information;
5
6@end
7
8@interface PNErrorStatus : PNStatus
9
10// Whether status object represent error or not.
11@property (nonatomic, readonly, assign, getter = isError) BOOL error;
12
13// Additional information related to error status object.
14@property (nonatomic, readonly, strong) PNErrorData *errorData;
15
Set user metadata
Unsupported partial updates of custom metadata
The value of the custom metadata parameter sent in this method always overwrites the value stored on PubNub servers. If you want to add new custom data to an existing one, you must:
- Get the existing metadata and store it locally.
- Append the new custom metadata to the existing one.
- Set the entire updated custom object.
Set metadata for a UUID in the database, optionally including the custom data object for each.
Method(s)
To Set UUID Metadata you can use the following method(s) in the Objective-C SDK:
1- (void)setUUIDMetadataWithRequest:(PNSetUUIDMetadataRequest *)request 
2                        completion:(nullable PNSetUUIDMetadataCompletionBlock)block;
| Parameter | Description | 
|---|---|
| request*Type: PNSetUUIDMetadataRequest | Request object for setting UUID metadata. | 
| blockType: PNSetUUIDMetadataCompletionBlock | Set UUID metadatarequest completionblock. | 
PNSetUUIDMetadataRequest
| Parameter | Description | 
|---|---|
| customType: NSDictionary | Additional / complex attributes which should be associated with metadata. App Context filtering language doesn't support filtering by custom properties. | 
| externalIdType: NSString | Identifier from external service (database, auth service). | 
| profileUrlType: NSString | URL at which profile available. | 
| includeFieldsType: PNUUIDFields | Bitfield of response fields. Supported: PNUUIDCustomField(custom set during UUID metadata set),PNUUIDStatusField(status set during UUID metadata set),PNUUIDTypeField(type set during UUID metadata set). | 
| emailType: NSString | Email address. | 
| nameType: NSString | Name which should be stored in metadata associated with specified identifier. | 
| uuidType: NSString | Create and configure set UUID metadata request. uuid- Identifier with which \c metadata is linked. Will be set to current PubNub configuration uuid if nil is set. | 
| statusType: NSString | The custom status of the user. | 
| typeType: NSString | The custom type of the user. | 
| ifMatchesEtagType: NSString | The entity tag to be used to ensure updates only happen if the object hasn't been modified since it was read. Use the eTag you received from an applicable get metadata method to check against the server entity tag. If the eTags don't match, an HTTP 412 error is thrown. | 
API limits
To learn about the maximum length of parameters used to set user metadata, refer to REST API docs.
Sample code
1PNSetUUIDMetadataRequest *request = [PNSetUUIDMetadataRequest requestWithUUID:@"uuid"];
2// With this option on, returned metadata model will have value which has been set to 'custom'
3// property.
4request.includeFields = PNUUIDCustomField;
5request.custom = @{ @"age": @(39), @"status": @"Checking some stuff..." };
6request.email = @"support@pubnub.com";
7request.name = @"David";
8
9[self.client setUUIDMetadataWithRequest:request completion:^(PNSetUUIDMetadataStatus *status) {
10    if (!status.isError) {
11        /**
12         * UUID metadata successfully has been set.
13         * UUID metadata information available here: status.data.metadata
14         */
15    } else {
Response
Response returned by the client for set UUID metadata:
1@interface PNSetUUIDMetadataData : PNServiceData
2
3// Updated UUID metadata object.
4@property (nonatomic, nullable, readonly, strong) PNUUIDMetadata *metadata;
5
6@end
7
8@interface PNSetUUIDMetadataStatus : PNAcknowledgmentStatus
9
10// Set UUID metadata request processed information.
11@property (nonatomic, readonly, strong) PNSetUUIDMetadataData *data;
12
13@end
Set user metadata (builder pattern)
Method(s)
1objects()
2    .setUUIDMetadata()
3    .uuid(NSString *)
4    .name(NSString *)
5    .externalId(NSString *)
6    .profileUrl(NSString *)
7    .custom(NSDictionary *)
8    .email(NSString *)
9    .includeFields(PNUUIDFields)
10    .performWithCompletion(nullable PNSetUUIDMetadataCompletionBlock);
API limits
To learn about the maximum length of parameters used to set user metadata, refer to REST API docs.
| Parameter | Description | 
|---|---|
| uuidType: NSString | Identifier with which new metadatashould be associated. Default: configured PubNub clientuuid | 
| nameType: NSString | Name which should stored in metadataassociated with specifiedUUID. | 
| externalIdType: NSString | External identifier (database, auth service) associated with specified UUID. | 
| profileUrlType: NSString | External URL with information for specified UUIDrepresentation. | 
| customType: NSDictionary | Additional information which should be stored in metadataassociated with specifiedUUID. App Context filtering language doesn't support filtering by custom properties. | 
| emailType: NSString | Email address which should be stored in metadataassociated with specifiedUUID. | 
| includeFieldsType: PNUUIDFields | Bitfield of response fields. Supported: PNUUIDCustomField(custom set during UUID metadata set),PNUUIDStatusField(status set during UUID metadata set),PNUUIDTypeField(type set during UUID metadata set). | 
| blockType: PNSetUUIDMetadataCompletionBlock | Set UUID metadatarequest completionblock. | 
Note
This method uses the builder pattern, you can remove the arguments which are optional.
Sample code
1self.client.objects().setUUIDMetadata()
2    .uuid(@"uuid")
3    .name(@"Serhii")
4    .externalId(@"93FVfHUAf4RLu79J7Q3ejLVu")
5    .profileUrl(@"https://pubnub.com")
6    .custom(@{ @"age": @(36) })
7    .email(@"support@pubnub.com")
8    .includeFields(PNUUIDCustomField)
9    .performWithCompletion(^(PNSetUUIDMetadataStatus *status) {
10        if (!status.isError) {
11            /**
12             * UUID metadata successfully has been set.
13             * UUID metadata information available here: status.data.metadata
14             */
15        } else {
Response
Response returned by the client for set UUID metadata:
1@interface PNSetUUIDMetadataData : PNServiceData
2
3// Updated UUID metadata object.
4@property (nonatomic, nullable, readonly, strong) PNUUIDMetadata *metadata;
5
6@end
7
8@interface PNSetUUIDMetadataStatus : PNAcknowledgmentStatus
9
10// Set UUID metadata request processed information.
11@property (nonatomic, readonly, strong) PNSetUUIDMetadataData *data;
12
13@end
Remove user metadata
Removes the metadata from a specified UUID.
Method(s)
To Remove UUID Metadata you can use the following method(s) in the Objective-C SDK:
1- (void)removeUUIDMetadataWithRequest:(PNRemoveUUIDMetadataRequest *)request 
2                           completion:(nullable PNRemoveUUIDMetadataCompletionBlock)block;
| Parameter | Description | 
|---|---|
| request* | Request object for removing UUID metadata. | 
| blockType: PNRemoveUUIDMetadataCompletionBlock | Remove UUID metadatarequest completionblock. | 
PNRemoveUUIDMetadataRequest
| Parameter | Description | 
|---|---|
| uuidType: NSString | Create and configure delete user request. identifier- Create and configure removeUUIDmetadata request. Will be set to current PubNub configuration uuid if nil is set. | 
Sample code
1PNRemoveUUIDMetadataRequest *request = [PNRemoveUUIDMetadataRequest requestWithUUID:@"uuid"];
2
3[self.client removeUUIDMetadataWithRequest:request completion:^(PNAcknowledgmentStatus *status) {
4    if (!status.isError) {
5        // UUID metadata successfully removed.
6    } else {
7        /**
8         * Handle UUID metadata remove error. Check 'category' property to find out possible
9         * issue because of which request did fail.
10         *
11         * Request can be resent using: [status retry]
12         */
13    }
14}];
Response
Response returned by the client for remove UUID metadata:
1@interface PNErrorData : PNServiceData
2
3// Stringified error information.
4@property (nonatomic, readonly, strong) NSString *information;
5
6@end
7
8@interface PNAcknowledgmentStatus : PNErrorStatus
9
10// Whether status object represent error or not.
11@property (nonatomic, readonly, assign, getter = isError) BOOL error;
12
13// Additional information related to error status object.
14@property (nonatomic, readonly, strong) PNErrorData *errorData;
15
Remove user metadata (builder pattern)
Method(s)
1objects()
2    .removeUUIDMetadata()
3    .uuid(NSString *)
4    .performWithCompletion(PNFetchUUIDMetadataCompletionBlock);
5
| Parameter | Description | 
|---|---|
| uuidType: NSString | Identifier for which associated metadatashould be removed. Default: configured PubNub clientuuid | 
| blockType: PNRemoveUUIDMetadataCompletionBlock | Remove UUID metadatarequest completionblock. | 
Note
This method uses the builder pattern, you can remove the arguments which are optional.
Sample code
1self.client.objects().removeUUIDMetadata()
2    .uuid(@"uuid")
3    .performWithCompletion(^(PNAcknowledgmentStatus *status) {
4        if (!status.isError) {
5             // User successfully deleted.
6        } else {
7            /**
8             * Handle user delete error. Check 'category' property to find out possible issue
9             * because of which request did fail.
10             *
11             * Request can be resent using: [status retry]
12             */
13        }
14    });
Response
Response returned by the client for remove UUID metadata:
1@interface PNErrorData : PNServiceData
2
3// Stringified error information.
4@property (nonatomic, readonly, strong) NSString *information;
5
6@end
7
8@interface PNAcknowledgmentStatus : PNErrorStatus
9
10// Whether status object represent error or not.
11@property (nonatomic, readonly, assign, getter = isError) BOOL error;
12
13// Additional information related to error status object.
14@property (nonatomic, readonly, strong) PNErrorData *errorData;
15
Channel
Get metadata for all channels
Returns a paginated list of Channel Metadata objects, optionally including the custom data object for each.
Method(s)
To Get All Channel Metadata you can use the following method(s) in the Objective-C SDK:
1- (void)allChannelsMetadataWithRequest:(PNFetchAllChannelsMetadataRequest *)request 
2                            completion:(PNFetchAllChannelsMetadataCompletionBlock)block;
| Parameter | Description | 
|---|---|
| request* | Request object for fetching all channel metadata. | 
| block*Type: PNFetchAllChannelsMetadataCompletionBlock | Completion block. | 
PNFetchAllChannelsMetadataRequest
| Parameter | Description | 
|---|---|
| includeFieldsType: PNChannelFields | Bitfield of response fields. Supported: PNChannelTotalCountField(number of channel metadata records),PNChannelCustomField(custom set during channel metadata set),PNChannelStatusField(status set during channel metadata set),PNChannelTypeField(type set during channel metadata set). Default isPNChannelTotalCountField(set 0 to reset). | 
| sortType: NSArray <NSString *> | List of criteria (name of field) which should be used for sorting in ascending order. Available options are id,name, andupdated. Useascordescto specify sort direction. For example:{name: 'asc'} | 
| filterType: NSString | Filter expression. Only matching objects are returned. See filtering. | 
| startType: NSString | Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off. | 
| endType: NSString | Cursor-based pagination. Ignored if the startparameter is supplied. | 
| limitType: NSUInteger | Number of objects to return. Default/Max: 100. | 
Sample code
1PNFetchAllChannelsMetadataRequest *request = [PNFetchAllChannelsMetadataRequest new];
2request.start = @"<next from previous request>";
3// Add this request option, if returned metadata models should have value which has been set to
4// 'custom' property.
5request.includeFields = PNUUIDCustomField | PNUUIDTotalCountField;
6request.limit = 40;
7
8[self.client allChannelsMetadataWithRequest:request
9                                 completion:^(PNFetchAllChannelsMetadataResult *result, PNErrorStatus *status) {
10    if (!status.isError) {
11        /**
12         * Channels metadata successfully fetched.
13         * Result object has following information:
14         *   result.data.metadata - List of fetched channels metadata.
15         *   result.data.next - Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
Response
Response returned by the client for fetch all UUID metadata:
1@interface PNFetchAllChannelsMetadataData : PNServiceData
2
3// List of channels metadata objects created for current subscribe key.
4@property (nonatomic, readonly, strong) NSArray<PNChannelMetadata *> *metadata;
5
6// Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
7@property (nonatomic, nullable, readonly, strong) NSString *next;
8
9// Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data.
10@property (nonatomic, nullable, readonly, strong) NSString *prev;
11
12/**
13 * Total number of objects created for current subscribe key.
14 *
15 * Value will be 0 in case if PNChannelTotalCountField not added to 'includeFields'
Error response which is used in case of App Context API call failure:
1@interface PNErrorData : PNServiceData
2
3// Stringified error information.
4@property (nonatomic, readonly, strong) NSString *information;
5
6@end
7
8@interface PNErrorStatus : PNStatus
9
10// Whether status object represent error or not.
11@property (nonatomic, readonly, assign, getter = isError) BOOL error;
12
13// Additional information related to error status object.
14@property (nonatomic, readonly, strong) PNErrorData *errorData;
15
Get metadata for all channels (builder pattern)
Method(s)
1objects()
2    .allChannelsMetadata()
3    .includeFields(PNChannelFields)
4    .includeCount(BOOL)
5    .filter(NSString)
6    .sort(NSArray)
7    .limit(NSUInteger)
8    .start(NSString)
9    .end(NSString)
10    .performWithCompletion(PNFetchChannelMetadataCompletionBlock);
| Parameter | Description | 
|---|---|
| includeFieldsType: PNChannelFields | Bitfield of response fields. Supported: PNChannelTotalCountField(number of channel metadata records),PNChannelCustomField(custom set during channel metadata set),PNChannelStatusField(status set during channel metadata set),PNChannelTypeField(type set during channel metadata set). Default isPNChannelTotalCountField(set 0 to reset). | 
| includeCountType: BOOL | Whether to include the total count in the paginated response. Default: YES | 
| filterType: NSString | Filter expression. Only matching objects are returned. See filtering. | 
| sortType: NSArray | Sort by id, name, updated with asc/desc for sort direction (for example, {name: 'asc'}). | 
| limitType: NSUInteger | Number of objects to return. Default/Max: 100. | 
| startType: NSString | Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off. | 
| endType: NSString | Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the startparameter is supplied. | 
| block*Type: PNFetchAllChannelsMetadataCompletionBlock | Fetch all UUID metadatarequest completionblock. | 
Note
This method uses the builder pattern, you can remove the arguments which are optional.
Sample code
1self.client.objects().allChannelsMetadata()
2    .start(@"<next from previous request>")
3    .includeFields(PNChannelCustomField)
4    .includeCount(YES)
5    .limit(40)
6    .performWithCompletion(^(PNFetchAllChannelsMetadataResult *result, PNErrorStatus *status) {
7        if (!status.isError) {
8            /**
9             * Channels metadata successfully fetched.
10             * Result object has following information:
11             *   result.data.metadata - List of fetched channels metadata.
12             *   result.data.next - Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
13             *   result.data.prev - Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data.
14             *   result.data.totalCount - Total number of associated channel metadata.
15        } else {
Response
Response returned by the client for fetch all UUID metadata:
1@interface PNFetchAllChannelsMetadataData : PNServiceData
2
3// List of channels metadata objects created for current subscribe key.
4@property (nonatomic, readonly, strong) NSArray<PNChannelMetadata *> *metadata;
5
6// Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
7@property (nonatomic, nullable, readonly, strong) NSString *next;
8
9// Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data.
10@property (nonatomic, nullable, readonly, strong) NSString *prev;
11
12/**
13 * Total number of objects created for current subscribe key.
14 *
15 * Value will be 0 in case if PNChannelTotalCountField not added to 'includeFields'
Error response which is used in case of App Context API call failure:
1@interface PNErrorData : PNServiceData
2
3// Stringified error information.
4@property (nonatomic, readonly, strong) NSString *information;
5
6@end
7
8@interface PNErrorStatus : PNStatus
9
10// Whether status object represent error or not.
11@property (nonatomic, readonly, assign, getter = isError) BOOL error;
12
13// Additional information related to error status object.
14@property (nonatomic, readonly, strong) PNErrorData *errorData;
15
Get channel metadata
Returns metadata for the specified Channel, optionally including the custom data object for each.
Method(s)
To Get Channel Metadata you can use the following method(s) in the Objective-C SDK:
1- (void)channelMetadataWithRequest:(PNFetchChannelMetadataRequest *)request 
2                        completion:(PNFetchChannelMetadataCompletionBlock)block;
| Parameter | Description | 
|---|---|
| request* | Request object for fetching channel metadata. | 
| block*Type: PNFetchChannelMetadataCompletionBlock | Completion block. | 
PNFetchChannelMetadataRequest
| Parameter | Description | 
|---|---|
| includeFieldsType: PNChannelFields | Bitfield of response fields. Supported: PNChannelCustomField(custom set during channel metadata set),PNChannelStatusField(status set during channel metadata set),PNChannelTypeField(type set during channel metadata set). | 
| channelType: NSString | Create and configure fetch channel metadata request. channel- Name of channel for which metadata should be fetched. | 
Sample code
1PNFetchChannelMetadataRequest *request = [PNFetchChannelMetadataRequest requestWithChannel:@"channel"];
2// Add this request option, if returned metadata model should have value which has been set to
3// 'custom' property.
4request.includeFields = PNChannelCustomField;
5
6[self.client channelMetadataWithRequest:request
7                             completion:^(PNFetchChannelsMetadataResult *result, PNErrorStatus *status) {
8
9    if (!status.isError) {
10        /**
11         * Channel metadata successfully fetched.
12         * Channel metadata information available here: result.data.metadata
13         */
14    } else {
15        /**
Response
Response returned by the client for fetch channel metadata:
1@interface PNFetchChannelMetadataData : PNServiceData
2
3// Requested channel metadata object.
4@property (nonatomic, nullable, readonly, strong) PNChannelMetadata *metadata;
5
6@end
7
8@interface PNFetchChannelsMetadataResult : PNResult
9
10// Fetch channel metadata request processed information.
11@property (nonatomic, readonly, strong) PNFetchChannelMetadataData *data;
12
13@end
Error response which is used in case of App Context API call failure:
1@interface PNErrorData : PNServiceData
2
3// Stringified error information.
4@property (nonatomic, readonly, strong) NSString *information;
5
6@end
7
8@interface PNErrorStatus : PNStatus
9
10// Whether status object represent error or not.
11@property (nonatomic, readonly, assign, getter = isError) BOOL error;
12
13// Additional information related to error status object.
14@property (nonatomic, readonly, strong) PNErrorData *errorData;
15
Get channel metadata (builder pattern)
Method(s)
1objects()
2    .channelMetadata(NSString *)
3    .includeFields(PNChannelFields)
4    .performWithCompletion(PNFetchChannelMetadataCompletionBlock);
| Parameter | Description | 
|---|---|
| channel*Type: NSString | Name of channel for which associated metadatashould be fetched. | 
| includeFieldsType: NSString | Bitfield set to fields which should be returned with response. Supported fields: 
 | 
| block*Type: PNFetchChannelMetadataCompletionBlock | Fetch channel metadatarequest completionblock. | 
Note
This method uses the builder pattern, you can remove the arguments which are optional.
Sample code
1self.client.objects().channelMetadata(@"channel")
2    .includeFields(PNChannelCustomField)
3    .performWithCompletion(^(PNFetchChannelsMetadataResult *result, PNErrorStatus *status) {
4        if (!status.isError) {
5            /**
6             * Channel metadata successfully fetched.
7             * Channel metadata information available here: result.data.metadata
8             */
9        } else {
10            /**
11             * Handle channel metadata fetch error. Check 'category' property to find out possible
12             * issue because of which request did fail.
13             *
14             * Request can be resent using: [status retry]
15             */
Response
Response returned by the client for fetch channel metadata:
1@interface PNFetchChannelMetadataData : PNServiceData
2
3// Requested channel metadata object.
4@property (nonatomic, nullable, readonly, strong) PNChannelMetadata *metadata;
5
6@end
7
8@interface PNFetchChannelsMetadataResult : PNResult
9
10// Fetch channel metadata request processed information.
11@property (nonatomic, readonly, strong) PNFetchChannelMetadataData *data;
12
13@end
Error response which is used in case of App Context API call failure:
1@interface PNErrorData : PNServiceData
2
3// Stringified error information.
4@property (nonatomic, readonly, strong) NSString *information;
5
6@end
7
8@interface PNErrorStatus : PNStatus
9
10// Whether status object represent error or not.
11@property (nonatomic, readonly, assign, getter = isError) BOOL error;
12
13// Additional information related to error status object.
14@property (nonatomic, readonly, strong) PNErrorData *errorData;
15
Set channel metadata
Unsupported partial updates of custom metadata
The value of the custom metadata parameter sent in this method always overwrites the value stored on PubNub servers. If you want to add new custom data to an existing one, you must:
- Get the existing metadata and store it locally.
- Append the new custom metadata to the existing one.
- Set the entire updated custom object.
Set metadata for a Channel in the database, optionally including the custom data object for each.
Method(s)
To Set Channel Metadata you can use the following method(s) in the Objective-C SDK:
1- (void)setChannelMetadataWithRequest:(PNSetChannelMetadataRequest *)request 
2                           completion:(nullable PNSetChannelMetadataCompletionBlock)block;
| Parameter | Description | 
|---|---|
| request* | Request object for setting channel metadata. | 
| blockType: PNSetChannelMetadataCompletionBlock | Set channel metadatarequest completionblock. | 
PNSetChannelMetadataRequest
| Parameter | Description | 
|---|---|
| customType: NSDictionary | Additional / complex attributes which should be stored in metadata associated with specified channel. App Context filtering language doesn't support filtering by custom properties. | 
| informationType: NSString | Description which should be stored in metadata associated with specified channel. | 
| includeFieldsType: PNChannelFields | Bitfield of response fields. Supported: PNChannelCustomField(custom set during channel metadata set),PNChannelStatusField(status set during channel metadata set),PNChannelTypeField(type set during channel metadata set). | 
| nameType: NSString | Name which should be stored in metadata associated with specified channel. | 
| channelType: NSString | Create and configure set channel metadata request. channel- Name of channel for which metadata should be set. | 
| statusType: NSString | The custom status of the channel. | 
| typeType: NSString | The custom type of the channel. | 
| ifMatchesEtagType: NSString | The entity tag to be used to ensure updates only happen if the object hasn't been modified since it was read. Use the eTag you received from an applicable get metadata method to check against the server entity tag. If the eTags don't match, an HTTP 412 error is thrown. | 
API limits
To learn about the maximum length of parameters used to set channel metadata, refer to REST API docs.
Sample code
1PNSetChannelMetadataRequest *request = [PNSetChannelMetadataRequest requestWithChannel:@"channel"];
2// Add this request option, if returned metadata model should have value which has been set to
3// 'custom' property.
4request.includeFields = PNChannelCustomField;
5request.custom = @{ @"responsibilities": @"Manage tests", @"status": @"offline" };
6request.name = @"Updated channel name";
7
8[self.client setChannelMetadataWithRequest:request completion:^(PNSetChannelMetadataStatus *status) {
9    if (!status.isError) {
10        /**
11         * Channel metadata successfully has been set.
12         * Channel metadata information available here: status.data.metadata
13         */
14    } else {
15        /**
Response
Response returned by the client for set channel metadata:
1@interface PNSetChannelMetadataData : PNServiceData
2
3// Associated channel's metadata object.
4@property (nonatomic, nullable, readonly, strong) PNChannelMetadata *metadata;
5
6@end
7
8@interface PNSetChannelMetadataStatus : PNAcknowledgmentStatus
9
10// Set channel metadata request processed information.
11@property (nonatomic, readonly, strong) PNSetChannelMetadataData *data;
12
13@end
Other examples
Iteratively update existing metadata
1#import <Foundation/Foundation.h>
2#import <PubNub/PubNub.h>
3
4// Assume 'client' is an initialized PubNub instance as shown in previous examples.
5// PubNub *client = [PubNub clientWithConfiguration:config];
6
7NSString *channel = @"demo_example";
8NSString *initialName = @"Initial Channel Name";
9NSString *initialDescription = @"Initial channel description.";
10NSDictionary *initialCustom = @{ @"location": @"default_location" };
11
12// First, set some initial metadata for the channel
13PNSetChannelMetadataRequest *initialSetRequest = [PNSetChannelMetadataRequest requestWithChannel:channel];
14initialSetRequest.name = initialName;
15initialSetRequest.information = initialDescription;
Set channel metadata (builder pattern)
Method(s)
1objects()
2    .setChannelMetadata(NSString *)
3    .includeFields(PNChannelFields)
4    .channel(NSString)
5    .name(NSString)
6    .information(NSString)
7    .custom(NSDictionary)
8    .performWithCompletion(PNFetchChannelMetadataCompletionBlock);
API limits
To learn about the maximum length of parameters used to set channel metadata, refer to REST API docs.
| Parameter | Description | 
|---|---|
| channel*Type: NSString | Name of channel with which new metadatashould be associated. | 
| nameType: NSString | Name which should stored in metadataassociated with specifiedchannel. | 
| informationType: NSString | Description which should be stored in metadataassociated with specifiedchannel. | 
| customType: NSDictionary | Additional information which should be stored in metadataassociated with specifiedchannel. App Context filtering language doesn't support filtering by custom properties. | 
| includeFieldsType: PNChannelFields | Bitfield of response fields. Supported: PNChannelCustomField(custom set during channel metadata set),PNChannelStatusField(status set during channel metadata set),PNChannelTypeField(type set during channel metadata set). | 
| blockType: PNSetChannelMetadataCompletionBlock | Set channel metadatarequest completionblock. | 
Note
This method uses the builder pattern, you can remove the arguments which are optional.
Sample code
1self.client.objects().setChannelMetadata(@"channel")
2    .name(@"Admin")
3    .information(@"Administrative channel")
4    .custom(@{ @"responsibilities": @"Manage access to protected resources" })
5    .includeFields(PNChannelCustomField)
6    .performWithCompletion(^(PNSetChannelMetadataStatus *status) {
7      if (!status.isError) {
8          /**
9           * Channel metadata successfully has been set.
10           * Channel metadata information available here: status.data.metadata
11           */
12      } else {
13          /**
14           * Handle channel metadata update error. Check 'category' property to find out possible
15           * issue because of which request did fail.
Response
Response returned by the client for set channel metadata:
1@interface PNSetChannelMetadataData : PNServiceData
2
3// Associated channel's metadata object.
4@property (nonatomic, nullable, readonly, strong) PNChannelMetadata *metadata;
5
6@end
7
8@interface PNSetChannelMetadataStatus : PNAcknowledgmentStatus
9
10// Set channel metadata request processed information.
11@property (nonatomic, readonly, strong) PNSetChannelMetadataData *data;
12
13@end
Remove channel metadata
Removes the metadata from a specified channel.
Method(s)
To Remove Channel Metadata you can use the following method(s) in the Objective-C SDK:
1- (void)removeChannelMetadataWithRequest:(PNRemoveChannelMetadataRequest *)request 
2                              completion:(nullable PNRemoveChannelMetadataCompletionBlock)block;
| Parameter | Description | 
|---|---|
| request* | Request object for removing channel metadata. | 
| blockType: PNRemoveChannelMetadataCompletionBlock | Remove channel metadatarequest completionblock. | 
PNRemoveChannelMetadataRequest
| Parameter | Description | 
|---|---|
| channelType: NSString | Create and configure remove channel metadata request. channel- Name of channel for which metadata should be removed. | 
Sample code
1PNRemoveChannelMetadataRequest *request = [PNRemoveChannelMetadataRequest requestWithChannel:@"channel"];
2
3[self.client removeChannelMetadataWithRequest:request completion:^(PNAcknowledgmentStatus *status) {
4    if (!status.isError) {
5        // Channel metadata successfully removed.
6    } else {
7        /**
8         * Handle channel metadata remove error. Check 'category' property to find out possible
9         * issue because of which request did fail.
10         *
11         * Request can be resent using: [status retry]
12         */
13    }
14}];
Response
Response returned by the client for remove channel metadata:
1@interface PNErrorData : PNServiceData
2
3// Stringified error information.
4@property (nonatomic, readonly, strong) NSString *information;
5
6@end
7
8@interface PNAcknowledgmentStatus : PNErrorStatus
9
10// Whether status object represent error or not.
11@property (nonatomic, readonly, assign, getter = isError) BOOL error;
12
13// Additional information related to error status object.
14@property (nonatomic, readonly, strong) PNErrorData *errorData;
15
Remove channel metadata (builder pattern)
Method(s)
1objects()
2    .removeChannelMetadata(NSString *)
3    .performWithCompletion(nullable PNRemoveChannelMetadataCompletionBlock);
| Parameter | Description | 
|---|---|
| channel*Type: NSString | Name of channel for which associated metadatashould be removed. | 
| blockType: PNRemoveChannelMetadataCompletionBlock | Remove channel metadatarequest completionblock. | 
Note
This method uses the builder pattern, you can remove the arguments which are optional.
Sample code
1self.client.objects().removeChannelMetadata(@"channel")
2    .performWithCompletion(^(PNAcknowledgmentStatus *status) {
3        if (!status.isError) {
4            // Channel metadata successfully removed.
5        } else {
6            /**
7             * Handle channel metadata remove error. Check 'category' property to find out possible
8             * issue because of which request did fail.
9             *
10             * Request can be resent using: [status retry]
11             */
12        }
13    });
Response
Response returned by the client for remove channel metadata:
1@interface PNErrorData : PNServiceData
2
3// Stringified error information.
4@property (nonatomic, readonly, strong) NSString *information;
5
6@end
7
8@interface PNAcknowledgmentStatus : PNErrorStatus
9
10// Whether status object represent error or not.
11@property (nonatomic, readonly, assign, getter = isError) BOOL error;
12
13// Additional information related to error status object.
14@property (nonatomic, readonly, strong) PNErrorData *errorData;
15
Channel memberships
Get channel memberships
The method returns a list of channel memberships for a user. This method doesn't return a user's subscriptions.
Method(s)
To Get Memberships you can use the following method(s) in the Objective-C SDK:
1- (void)membershipsWithRequest:(PNFetchMembershipsRequest *)request 
2                    completion:(PNFetchMembershipsCompletionBlock)block;
| Parameter | Description | 
|---|---|
| request* | Request object for fetching UUID memberships. | 
| block*Type: PNFetchMembershipsCompletionBlock | Completion block. | 
PNFetchMembershipsRequest
| Parameter | Description | 
|---|---|
| sortType: NSArray <NSString *> | Sort by id, name, updated with asc/desc for sort direction (for example, {name: 'asc'}). | 
| includeFieldsType: PNMembershipFields | Bitfield of response fields. Supported: PNMembershipsTotalCountField(number of memberships),PNMembershipCustomField(custom set during membership set),PNMembershipStatusField(status set during membership set),PNMembershipTypeField(type set during membership set),PNMembershipChannelField(include channel metadata),PNMembershipChannelCustomField(channel custom set during channel metadata set),PNMembershipChannelStatusField(channel status set during channel metadata set),PNMembershipChannelTypeField(channel type set during channel metadata set). Default isPNMembershipsTotalCountField(set 0 to reset). | 
| filterType: NSString | Filter expression. Only matching objects are returned. See filtering. | 
| startType: NSString | Cursor-based pagination. | 
| endType: NSString | Cursor-based pagination. Ignored if the startparameter is supplied. | 
| limitType: NSUInteger | Number of objects to return. Default/Max: 100. | 
Sample code
1PNFetchMembershipsRequest *request = [PNFetchMembershipsRequest requestWithUUID:@"uuid"];
2request.start = @"<next from previous request>";
3// Add this request option, if returned membership models should have value which has been set to
4// 'custom' and 'channel' properties.
5request.includeFields = PNMembershipCustomField | PNMembershipChannelField | PNMembershipsTotalCountField;
6request.limit = 40;
7
8[self.client membershipsWithRequest:request
9                         completion:^(PNFetchMembershipsResult *result, PNErrorStatus *status) {
10
11    if (!status.isError) {
12        /**
13         * UUID's memberships successfully fetched.
14         * Result object has following information:
15         *   result.data.memberships - List of UUID's memberships.
Response
Response returned by the client for fetch memberships:
1@interface PNFetchMembershipsData : PNServiceData
2
3// List of fetched memberships.
4@property (nonatomic, readonly, strong) NSArray<PNMembership *> *memberships;
5
6// Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
7@property (nonatomic, nullable, readonly, strong) NSString *next;
8
9// Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data.
10@property (nonatomic, nullable, readonly, strong) NSString *prev;
11
12/**
13 * Total number of members created for current subscribe key.
14 *
15 * Value will be 0 in case if PNMembershipsTotalCountField not added to 'includeFields'
Error response which is used in case of App Context API call failure:
1@interface PNErrorData : PNServiceData
2
3// Stringified error information.
4@property (nonatomic, readonly, strong) NSString *information;
5
6@end
7
8@interface PNErrorStatus : PNStatus
9
10// Whether status object represent error or not.
11@property (nonatomic, readonly, assign, getter = isError) BOOL error;
12
13// Additional information related to error status object.
14@property (nonatomic, readonly, strong) PNErrorData *errorData;
15
Get channel memberships (builder pattern)
Method(s)
1objects()
2    .memberships()
3    .uuid(NSString *)
4    .includeFields(PNMembershipFields)
5    .includeCount(BOOL)
6    .filter(NSString *)
7    .sort(NSArray<NSString *> *)
8    .limit(NSUInteger)
9    .start(NSString *)
10    .end(NSString *)
11    .performWithCompletion(PNFetchMembershipsCompletionBlock);
| Parameter | Description | 
|---|---|
| uuidType: NSString | Name of channel from which members should be fetched. | 
| includeFieldsType: PNMembershipFields | Bitfield of response fields. Supported: PNMembershipsTotalCountField(number of memberships),PNMembershipCustomField(custom set during membership set),PNMembershipStatusField(status set during membership set),PNMembershipTypeField(type set during membership set),PNMembershipChannelField(include channel metadata),PNMembershipChannelCustomField(channel custom set during channel metadata set),PNMembershipChannelStatusField(channel status set during channel metadata set),PNMembershipChannelTypeField(channel type set during channel metadata set). Default isPNMembershipsTotalCountField(set 0 to reset). | 
| includeCountType: BOOL | Whether to include the total count in the paginated response. Default: YES | 
| filterType: NSString | Filter expression. Only matching objects are returned. See filtering. | 
| sortType: NSArray | List of criteria (name of field) which should be used for sorting in ascending order. Available options are id,name, andupdated. Useascordescto specify sort direction. For example:{name: 'asc'} | 
| limitType: NSUInteger | Number of objects to return. Default/Max: 100. | 
| startType: NSString | Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off. | 
| endType: NSString | Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the startparameter is supplied. | 
| block*Type: PNFetchMembershipsCompletionBlock | Fetch UUID's membershipsrequest completionblock. | 
Note
This method uses the builder pattern, you can remove the arguments which are optional.
Sample code
1self.client.objects().memberships()
2    .uuid(@"uuid")
3    .includeCount(YES)
4    .limit(40)
5    .includeFields(PNMembershipCustomField | PNMembershipChannelField)
6    .performWithCompletion(^(PNFetchMembershipsResult *result, PNErrorStatus *status) {
7        if (!status.isError) {
8            /**
9             * UUID's memberships successfully fetched.
10             * Result object has following information:
11             *   result.data.memberships - List of UUID's memberships.
12             *   result.data.next - Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
13             *   result.data.prev - Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data.
14             *   result.data.totalCount - Total number of UUID's memberships.
15             */
Response
Response returned by the client for fetch memberships:
1@interface PNFetchMembershipsData : PNServiceData
2
3// List of fetched memberships.
4@property (nonatomic, readonly, strong) NSArray<PNMembership *> *memberships;
5
6// Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
7@property (nonatomic, nullable, readonly, strong) NSString *next;
8
9// Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data.
10@property (nonatomic, nullable, readonly, strong) NSString *prev;
11
12/**
13 * Total number of members created for current subscribe key.
14 *
15 * Value will be 0 in case if PNMembershipsTotalCountField not added to 'includeFields'
Error response which is used in case of App Context API call failure:
1@interface PNErrorData : PNServiceData
2
3// Stringified error information.
4@property (nonatomic, readonly, strong) NSString *information;
5
6@end
7
8@interface PNErrorStatus : PNStatus
9
10// Whether status object represent error or not.
11@property (nonatomic, readonly, assign, getter = isError) BOOL error;
12
13// Additional information related to error status object.
14@property (nonatomic, readonly, strong) PNErrorData *errorData;
15
Set channel memberships
Set channel memberships for a UUID.
Method(s)
To Set Memberships you can use the following method(s) in the Objective-C SDK:
1- (void)setMembershipsWithRequest:(PNSetMembershipsRequest *)request 
2                       completion:(nullable PNManageMembershipsCompletionBlock)block;
| Parameter | Description | 
|---|---|
| request*Type: PNSetMembershipsRequest | Request object for setting UUID memberships. | 
| blockType: PNManageMembershipsCompletionBlock | Set UUID's membershipsrequest completionblock. | 
PNSetMembershipsRequest
| Parameter | Description | 
|---|---|
| sortType: NSArray <NSString *> | List of criteria (name of field) which should be used for sorting in ascending order. Available options are id,name, andupdated. Useascordescto specify sort direction. For example:{name: 'asc'} | 
| includeFieldsType: PNMembershipFields | Bitfield set to fields which should be returned with response. Supported fields: 
 | 
| filterType: NSString | Filter expression. Only matching objects are returned. See filtering. | 
| startType: NSString | Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off. | 
| endType: NSString | Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the startparameter is supplied. | 
| limitType: NSUInteger | Number of objects to return. Default/Max: 100. | 
API limits
To learn about the maximum length of parameters used to set channel membership metadata, refer to REST API docs.
Sample code
1NSArray<NSDictionary *> *channels = @[
2  @{ 
3    @"channel": @"channel1", 
4    @"status": @"active",
5    @"type": @"public", 
6    @"custom": @{ @"role": @"moderator" } 
7  }
8];
9
10PNSetMembershipsRequest *request = [PNSetMembershipsRequest requestWithUUID:@"uuid"
11                                                                   channels:channels];
12// Add this request option, if returned membership models should have value which has been set to
13// 'custom' and 'channel' properties.
14request.includeFields = PNMembershipCustomField | PNMembershipChannelField | PNMembershipsTotalCountField;
15request.limit = 40;
Response
Response returned by the client for set memberships:
1@interface PNManageMembershipsData : PNServiceData
2
3// List of existing memberships.
4@property (nonatomic, readonly, strong) NSArray<PNMembership *> *memberships;
5
6// Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
7@property (nonatomic, nullable, readonly, strong) NSString *next;
8
9// Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data.
10@property (nonatomic, nullable, readonly, strong) NSString *prev;
11
12/**
13 * Total number of existing objects.
14 *
15 * Value will be 0 in case if PNMembershipsTotalCountField not added to 'includeFields'
Set channel memberships (builder pattern)
Method(s)
1objects()
2    .setMemberships()
3    .uuid(NSString *)
4    .channels(NSArray<NSDictionary *> *)
5    .includeFields(PNMembershipFields)
6    .includeCount(BOOL)
7    .filter(NSString *)
8    .sort(NSArray<NSString *> *)
9    .limit(NSUInteger)
10    .start(NSString *)
11    .end(NSString *)
12    .performWithCompletion(nullable PNManageMembershipsCompletionBlock);
API limits
To learn about the maximum length of parameters used to set channel membership metadata, refer to REST API docs.
| Parameter | Description | 
|---|---|
| uuidType: NSString | Identifier for which memberships should be set. Default: configured PubNub client uuid | 
| channelsType: NSArray | List of channelsfor whichmetadataassociated with each of them in context ofUUIDshould be set. Each entry is dictionary withchannelandoptionalcustomfields.customshould be dictionary with simple objects:NSStringandNSNumber. | 
| includeFieldsType: PNMembershipFields | Bitfield set to fields which should be returned with response. Supported fields: 
 | 
| includeCountType: BOOL | Whether to include the total count in the paginated response. Default: YES | 
| filterType: NSString | Filter expression. Only matching objects are returned. See filtering. | 
| sortType: NSArray | List of criteria (name of field) which should be used for sorting in ascending order. Available options are id,name, andupdated. Useascordescto specify sort direction. For example:{name: 'asc'} | 
| limitType: NSUInteger | Number of objects to return. Default/Max: 100. | 
| startType: NSString | Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off. | 
| endType: NSString | Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the startparameter is supplied. | 
| blockType: PNManageMembershipsCompletionBlock | Set UUID's membershipsrequest completionblock. | 
Note
This method uses the builder pattern, you can remove the arguments which are optional.
Sample code
1NSArray<NSDictionary *> *channels = @[
2  @{ 
3    @"channel": @"channel1", 
4    @"status": @"active",
5    @"type": @"public", 
6    @"custom": @{ @"role": @"moderator" } 
7  }
8];
9
10self.client.objects().setMemberships()
11    .uuid(@"uuid")
12    .channels(channels)
13    .includeCount(YES)
14    .limit(40)
15    .includeFields(NMembershipCustomField | PNMembershipChannelField)
Response
Response returned by the client for set memberships:
1@interface PNManageMembershipsData : PNServiceData
2
3// List of existing memberships.
4@property (nonatomic, readonly, strong) NSArray<PNMembership *> *memberships;
5
6// Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
7@property (nonatomic, nullable, readonly, strong) NSString *next;
8
9// Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data.
10@property (nonatomic, nullable, readonly, strong) NSString *prev;
11
12/**
13 * Total number of existing objects.
14 *
15 * Value will be 0 in case if PNMembershipsTotalCountField not added to 'includeFields'
Remove channel memberships
Remove channel memberships for a UUID.
Method(s)
To Remove Memberships you can use the following method(s) in the Objective-C SDK:
1- (void)removeMembershipsWithRequest:(PNRemoveMembershipsRequest *)request 
2                          completion:(nullable PNManageMembershipsCompletionBlock)block;
| Parameter | Description | 
|---|---|
| request* | Request object for removing UUID memberships. | 
| blockType: PNManageMembershipsCompletionBlock | Remove UUID's membershipsrequest completion block. | 
PNRemoveMembershipsRequest
| Parameter | Description | 
|---|---|
| sortType: NSArray <NSString *> | List of criteria (name of field) which should be used for sorting in ascending order. Available options are id,name, andupdated. Useascordescto specify sort direction. For example:{name: 'asc'} | 
| includeFieldsType: PNMembershipFields | Bitfield set to fields which should be returned with response. Supported fields: 
 | 
| filterType: NSString | Filter expression. Only matching objects are returned. See filtering. | 
| startType: NSString | Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off. | 
| endType: NSString | Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the startparameter is supplied. | 
| limitType: NSUInteger | Number of objects to return. Default/Max: 100. | 
Sample code
1NSArray<NSString *> *channels = @[@"channel1", @"channel2"];
2PNRemoveMembershipsRequest *request = [PNRemoveMembershipsRequest requestWithUUID:@"uuid"
3                                                                         channels:channels];
4// Add this request option, if returned membership models should have value which has been set to
5// 'custom' and 'channel' properties.
6request.includeFields = PNMembershipCustomField | PNMembershipChannelField | PNMembershipsTotalCountField;
7request.limit = 40;
8
9[self.client removeMembershipsWithRequest:request
10                               completion:^(PNManageMembershipsStatus *status) {
11
12    if (!status.isError) {
13        /**
14         * UUID's memberships successfully removed.
15         * Result object has following information:
Response
Response returned by the client for remove memberships:
1@interface PNManageMembershipsData : PNServiceData
2
3// List of existing memberships.
4@property (nonatomic, readonly, strong) NSArray<PNMembership *> *memberships;
5
6// Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
7@property (nonatomic, nullable, readonly, strong) NSString *next;
8
9// Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data.
10@property (nonatomic, nullable, readonly, strong) NSString *prev;
11
12/**
13 * Total number of existing objects.
14 *
15 * Value will be 0 in case if PNMembershipsTotalCountField not added to 'includeFields'
Remove channel memberships (builder pattern)
Method(s)
1objects()
2    .removeMemberships()
3    .uuid(NSString *)
4    .channels(NSArray<NSString *> *)
5    .includeFields(PNMemberFields)
6    .includeCount(BOOL)
7    .filter(NSString *)
8    .sort(NSArray<NSString *> *)
9    .limit(NSUInteger)
10    .start(NSString *)
11    .end(NSString *)
12    .performWithCompletion(nullable PNManageMembershipsCompletionBlock);
| Parameter | Description | 
|---|---|
| uuidType: NSString | Identifier for which memberships should be removed. Default: configured PubNub client uuid | 
| channelsType: NSArray | List of channelsfrom whichUUIDshould be removed asmember. | 
| includeFieldsType: PNMembershipFields | Bitfield set to fields which should be returned with response. Supported fields: 
 | 
| includeCountType: BOOL | Whether to include the total count in the paginated response. Default: YES | 
| filterType: NSString | Filter expression. Only matching objects are returned. See filtering. | 
| sortType: NSArray | List of criteria (name of field) which should be used for sorting in ascending order. Available options are id,name, andupdated. Useascordescto specify sort direction. For example:{name: 'asc'} | 
| limitType: NSUInteger | Number of objects to return. Default/Max: 100. | 
| startType: NSString | Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off. | 
| endType: NSString | Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the startparameter is supplied. | 
| blockType: PNManageMembershipsCompletionBlock | Remove UUID's membershipsrequest completion block. | 
Note
This method uses the builder pattern, you can remove the arguments which are optional.
Sample code
1self.client.objects().removeMemberships()
2    .uuid(@"uuid")
3    .channels(@[@"channel1", @"channel2"])
4    .includeCount(YES)
5    .limit(40)
6    .includeFields(PNMembershipCustomField | PNMembershipChannelField)
7    .performWithCompletion(^(PNManageMembershipsStatus *status) {
8        if (!status.isError) {
9            /**
10             * UUID's memberships successfully removed.
11             * Result object has following information:
12             *   status.data.memberships - List of UUID's existing memberships.
13             *   status.data.next - Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
14             *   status.data.prev - Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data.
15             *   status.data.totalCount - Total number of UUID's memberships.
Response
Response returned by the client for remove memberships:
1@interface PNManageMembershipsData : PNServiceData
2
3// List of existing memberships.
4@property (nonatomic, readonly, strong) NSArray<PNMembership *> *memberships;
5
6// Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
7@property (nonatomic, nullable, readonly, strong) NSString *next;
8
9// Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data.
10@property (nonatomic, nullable, readonly, strong) NSString *prev;
11
12/**
13 * Total number of existing objects.
14 *
15 * Value will be 0 in case if PNMembershipsTotalCountField not added to 'includeFields'
Manage channel memberships
The method Set and Remove channel memberships for a user.
Method(s)
To Manage Memberships you can use the following method(s) in the Objective-C SDK:
1- (void)manageMembershipsWithRequest:(PNManageMembershipsRequest *)request 
2                          completion:(nullable PNManageMembershipsCompletionBlock)block;
| Parameter | Description | 
|---|---|
| request* | Request object for managing UUID memberships. | 
| blockType: PNManageMembershipsCompletionBlock | Manage UUID's membershipsrequest completionblock. | 
PNManageMembershipsRequest
| Parameter | Description | 
|---|---|
| setChannelsType: NSArray <NSDictionary *> | List of channels within which UUID should be set as member. Each entry is dictionary with channel and optional customfields.customshould be dictionary with simple objects: NSString and NSNumber. | 
| removeChannelsType: NSArray <NSString *> | List of channels from which UUID should be removed as member. | 
| sortType: NSArray <NSString *> | List of criteria (name of field) which should be used for sorting in ascending order. Available options are id,name, andupdated. Useascordescto specify sort direction. For example:{name: 'asc'} | 
| includeFieldsType: PNMembershipFields | Bitfield set to fields which should be returned with response. Supported fields: 
 | 
| filterType: NSString | Filter expression. Only matching objects are returned. See filtering. | 
| startType: NSString | Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off. | 
| endType: NSString | Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the startparameter is supplied. | 
| limitType: NSUInteger | Number of objects to return. Default/Max: 100. | 
Sample code
1PNManageMembershipsRequest *request = [PNManageMembershipsRequest requestWithUUID:@"uuid"];
2request.setChannels = @[
3    @{ @"channel": @"channel1", @"custom": @{ @"role": @"moderator" } }
4];
5request.removeChannels = @[@"channel3", @"channel4"];
6// Add this request option, if returned membership models should have value which has been set to
7// 'custom' and 'channel' properties.
8request.includeFields = PNMembershipCustomField | PNMembershipChannelField | PNMembershipsTotalCountField;
9request.limit = 40;
10
11[self.client manageMembershipsWithRequest:request
12                               completion:^(PNManageMembershipsStatus *status) {
13
14    if (!status.isError) {
15        /**
Response
Response returned by the client for manage memberships:
1@interface PNManageMembershipsData : PNServiceData
2
3// List of existing memberships.
4@property (nonatomic, readonly, strong) NSArray<PNMembership *> *memberships;
5
6// Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
7@property (nonatomic, nullable, readonly, strong) NSString *next;
8
9// Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data.
10@property (nonatomic, nullable, readonly, strong) NSString *prev;
11
12/**
13 * Total number of existing objects.
14 *
15 * Value will be 0 in case if PNMembershipsTotalCountField not added to 'includeFields'
Manage channel memberships (builder pattern)
Method(s)
1objects()
2    .manageMemberships()
3    .uuid(NSString *)
4    .set(NSArray<NSDictionary *> *)
5    .remove(NSArray<NSString *> *)
6    .includeFields(PNMemberFields)
7    .includeCount(BOOL)
8    .filter(NSString *)
9    .sort(NSArray<NSString *> *)
10    .limit(NSUInteger)
11    .start(NSString *)
12    .end(NSString *)
13    .performWithCompletion(nullable PNManageMembershipsCompletionBlock);
| Parameter | Description | 
|---|---|
| uuidType: NSString | Identifier for which memberships should be set. Default: configured PubNub client uuid | 
| setType: NSArray | List of channelsfor whichmetadataassociated with each of them in context ofUUIDshould be set. Each entry is dictionary withchannelandoptionalcustomfields.customshould be dictionary with simple objects:NSStringandNSNumber. | 
| removeType: NSArray | List of channelsfrom whichUUIDshould be removed asmember. | 
| includeFieldsType: PNMembershipFields | Bitfield set to fields which should be returned with response. Supported fields: 
 | 
| includeCountType: BOOL | Whether to include the total count in the paginated response. Default: YES | 
| filterType: NSString | Filter expression. Only matching objects are returned. See filtering. | 
| sortType: NSArray | List of criteria (name of field) which should be used for sorting in ascending order. Available options are id,name, andupdated. Useascordescto specify sort direction. For example:{name: 'asc'} | 
| limitType: NSUInteger | Number of objects to return. Default/Max: 100. | 
| startType: NSString | Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off. | 
| endType: NSString | Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the startparameter is supplied. | 
| blockType: PNManageMembershipsCompletionBlock | Manage UUID's membershipsrequest completionblock. | 
Note
This method uses the builder pattern, you can remove the arguments which are optional.
Sample code
1NSArray<NSDictionary *> *setChannels = @[
2    @{ @"channel": @"channel1", @"custom": @{ @"role": @"moderator" } }
3];
4NSArray<NSString *> *removeChannels = @[@"channel3", @"channel4"];
5
6self.client.objects().manageMemberships()
7    .uuid(@"uuid")
8    .set(setChannels)
9    .remove(removeChannels)
10    .includeCount(YES)
11    .limit(40)
12    .includeFields(PNMembershipCustomField | PNMembershipChannelField)
13    .performWithCompletion(^(PNManageMembershipsStatus *status) {
14        if (!status.isError) {
15            /**
Response
Response returned by the client for manage memberships:
1@interface PNManageMembershipsData : PNServiceData
2
3// List of existing memberships.
4@property (nonatomic, readonly, strong) NSArray<PNMembership *> *memberships;
5
6// Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
7@property (nonatomic, nullable, readonly, strong) NSString *next;
8
9// Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data.
10@property (nonatomic, nullable, readonly, strong) NSString *prev;
11
12/**
13 * Total number of existing objects.
14 *
15 * Value will be 0 in case if PNMembershipsTotalCountField not added to 'includeFields'
Channel members
Get channel members
The method returns a list of members in a channel. The list will include user metadata for members that have additional metadata stored in the database.
Method(s)
To Get Channel Members you can use the following method(s) in the Objective-C SDK:
1- (void)channelMembersWithRequest:(PNFetchChannelMembersRequest *)request 
2                       completion:(PNFetchChannelMembersCompletionBlock)block;
| Parameter | Description | 
|---|---|
| request* | Request object for fetching channel members. | 
| block*Type: PNFetchChannelMembersCompletionBlock | Completion block. | 
PNFetchChannelMembersRequest
| Parameter | Description | 
|---|---|
| sortType: NSArray <NSString *> | List of criteria (name of field) which should be used for sorting in ascending order. Available options are id,name, andupdated. Useascordescto specify sort direction. For example:{name: 'asc'} | 
| includeFieldsType: PNChannelMemberFields | Bitfield set to fields that should be returned with the response. Supported fields: 
 PNChannelMembersTotalCountField) can be reset by setting it to 0. | 
| filterType: NSString | Filter expression. Only matching objects are returned. See filtering. | 
| startType: NSString | Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off. | 
| endType: NSString | Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the startparameter is supplied. | 
| limitType: NSUInteger | Number of objects to return. Default/Max: 100. | 
Sample code
1PNFetchChannelMembersRequest *request = [PNFetchChannelMembersRequest requestWithChannel:@"channel"];
2request.start = @"<next from previous request>";
3// Add this request option, if returned member models should have value which has been set to
4// 'custom' and 'uuid' properties.
5request.includeFields = PNChannelMemberCustomField | PNChannelMemberUUIDField | PNChannelMembersTotalCountField;
6request.limit = 40;
7
8[self.client channelMembersWithRequest:request
9                            completion:^(PNFetchChannelMembersResult *result, PNErrorStatus *status) {
10
11    if (!status.isError) {
12        /**
13         * Channel's members successfully fetched.
14         * Result object has following information:
15         *   result.data.members - List of channel's members.
Response
Response returned by the client for fetch members:
1@interface PNFetchChannelMembersData : PNServiceData
2
3// List of fetched members.
4@property (nonatomic, readonly, strong) NSArray<PNChannelMember *> *members;
5
6// Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
7@property (nonatomic, nullable, readonly, strong) NSString *next;
8
9// Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data.
10@property (nonatomic, nullable, readonly, strong) NSString *prev;
11
12/**
13 * Total number of members created for current subscribe key.
14 *
15 * Value will be 0 in case if PNChannelMembersTotalCountField not added to 'includeFields'
Error response which is used in case of App Context API call failure:
1@interface PNErrorData : PNServiceData
2
3// Stringified error information.
4@property (nonatomic, readonly, strong) NSString *information;
5
6@end
7
8@interface PNErrorStatus : PNStatus
9
10// Whether status object represent error or not.
11@property (nonatomic, readonly, assign, getter = isError) BOOL error;
12
13// Additional information related to error status object.
14@property (nonatomic, readonly, strong) PNErrorData *errorData;
15
Get channel members (builder pattern)
Method(s)
1objects()
2    .channelMembers(NSString *)
3    .includeFields(PNChannelMemberFields)
4    .includeCount(BOOL)
5    .filter(NSString *)
6    .sort(NSArray<NSString *> *)
7    .limit(NSUInteger)
8    .start(NSString *)
9    .end(NSString *)
10    .performWithCompletion(PNFetchChannelMembersCompletionBlock);
| Parameter | Description | 
|---|---|
| channel*Type: NSString | Name of channel from which members should be fetched. | 
| includeFieldsType: PNChannelMemberFields | Bitfield set to fields that should be returned with the response. Supported fields: 
 PNChannelMembersTotalCountField) can be reset by setting it to 0. | 
| includeCountType: BOOL | Whether to include the total count in the paginated response. Default: YES | 
| filterType: NSString | Expression to filter out results basing on specified criteria. For more details on the supported grammar, check this | 
| sortType: NSArray | List of criteria (name of field) which should be used for sorting in ascending order. Available options are id,name, andupdated. Useascordescto specify sort direction. For example:{name: 'asc'} | 
| limitType: NSUInteger | Number of objects to return. Default/Max: 100. | 
| startType: NSString | Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off. | 
| endType: NSString | Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the startparameter is supplied. | 
| block*Type: PNFetchChannelMembersCompletionBlock | Fetch channel's membersrequest completion block. | 
Note
This method uses the builder pattern, you can remove the arguments which are optional.
Sample code
1self.client.objects().channelMembers(@"channel")
2    .includeCount(YES)
3    .limit(40)
4    .includeFields(PNChannelMemberCustomField | PNChannelMemberUUIDField)
5    .performWithCompletion(^(PNFetchChannelMembersResult *result, PNErrorStatus *status) {
6        if (!status.isError) {
7            /**
8             * Channel's members successfully fetched.
9             * Result object has following information:
10             *   result.data.members - List of channel's members.
11             *   result.data.next - Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
12             *   result.data.prev - Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data.
13             *   result.data.totalCount - Total number of channel's members.
14             */
15        } else {
Response
Response returned by the client for fetch members:
1@interface PNFetchChannelMembersData : PNServiceData
2
3// List of fetched members.
4@property (nonatomic, readonly, strong) NSArray<PNChannelMember *> *members;
5
6// Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
7@property (nonatomic, nullable, readonly, strong) NSString *next;
8
9// Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data.
10@property (nonatomic, nullable, readonly, strong) NSString *prev;
11
12/**
13 * Total number of members created for current subscribe key.
14 *
15 * Value will be 0 in case if PNChannelMembersTotalCountField not added to 'includeFields'
Error response which is used in case of App Context API call failure:
1@interface PNErrorData : PNServiceData
2
3// Stringified error information.
4@property (nonatomic, readonly, strong) NSString *information;
5
6@end
7
8@interface PNErrorStatus : PNStatus
9
10// Whether status object represent error or not.
11@property (nonatomic, readonly, assign, getter = isError) BOOL error;
12
13// Additional information related to error status object.
14@property (nonatomic, readonly, strong) PNErrorData *errorData;
15
Set channel members
This method sets members in a channel.
Method(s)
To Set Channel Members you can use the following method(s) in the Objective-C SDK:
1- (void)setChannelMembersWithRequest:(PNSetChannelMembersRequest *)request 
2                          completion:(nullable PNManageChannelMembersCompletionBlock)block;
| Parameter | Description | 
|---|---|
| request* | Request object for setting channel members. | 
| blockType: PNManageChannelMembersCompletionBlock | Set channel's memberslist request completionblock. | 
PNSetMembersRequest
| Parameter | Description | 
|---|---|
| sortType: NSArray <NSString *> | List of criteria (name of field) which should be used for sorting in ascending order. Available options are id,name, andupdated. Useascordescto specify sort direction. For example:{name: 'asc'} | 
| includeFieldsType: PNChannelMemberFields | Bitfield set to fields that should be returned with the response. Supported fields: 
 PNChannelMembersTotalCountField) can be reset by setting it to 0. | 
| filterType: NSString | Expression to filter out results basing on specified criteria. For more details on the supported grammar, check this | 
| startType: NSString | Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off. | 
| endType: NSString | Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the startparameter is supplied. | 
| limitType: NSUInteger | Number of objects to return. Default/Max: 100. | 
API limits
To learn about the maximum length of parameters used to set channel members metadata, refer to REST API docs.
Sample code
1NSArray<NSDictionary *> *uuids = @[
2  @{ 
3    @"uuid": @"uuid2"
4    @"status": @"active",
5    @"type": @"admin",
6    @"custom": @{ @"role": @"moderator" } 
7  }
8];
9
10PNSetChannelMembersRequest *request = [PNSetChannelMembersRequest requestWithChannel:@"channel" uuids:uuids];
11// Add this request option, if returned member models should have value which has been set to
12// 'custom' and 'uuid' properties.
13request.includeFields = PNChannelMemberCustomField | PNChannelMemberUUIDField | PNChannelMembersTotalCountField;
14request.limit = 40;
15
Response
Response returned by the client for set members:
1@interface PNManageChannelMembersData : PNServiceData
2
3// List of existing members.
4@property (nonatomic, readonly, strong) NSArray<PNChannelMember *> *members;
5
6// Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
7@property (nonatomic, nullable, readonly, strong) NSString *next;
8
9// Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data.
10@property (nonatomic, nullable, readonly, strong) NSString *prev;
11
12/**
13 * Total number of existing objects.
14 *
15 * Value will be 0 in case if PNChannelMembersTotalCountField not added to 'includeFields'
Set channel members (builder pattern)
Method(s)
1objects()
2    .setChannelMembers(NSString *)
3    .uuids(NSArray<NSDictionary *> *)
4    .includeFields(PNChannelMemberFields)
5    .includeCount(BOOL)
6    .filter(NSString *)
7    .sort(NSArray<NSString *> *)
8    .limit(NSUInteger)
9    .start(NSString *)
10    .end(NSString *)
11    .performWithCompletion(nullable PNManageChannelMembersCompletionBlock);
API limits
To learn about the maximum length of parameters used to set channel members metadata, refer to REST API docs.
| Parameter | Description | 
|---|---|
| channel*Type: NSString | Name of channel from which members should be set. | 
| uuidsType: NSArray | List of UUIDsfor whichmetadataassociated with each of them in context ofchannelshould be set. Each entry is dictionary withUUIDandoptionalcustomfields.customshould be dictionary with simple objects:NSStringandNSNumber. | 
| includeFieldsType: PNChannelMemberFields | Bitfield set to fields that should be returned with the response. Supported fields: 
 PNChannelMembersTotalCountField) can be reset by setting it to 0. | 
| includeCountType: BOOL | Whether to include the total count in the paginated response. Default: YES | 
| filterType: NSString | Filter expression. Only matching objects are returned. See filtering. | 
| sortType: NSArray | List of criteria (name of field) which should be used for sorting in ascending order. Available options are id,name, andupdated. Useascordescto specify sort direction. For example:{name: 'asc'} | 
| limitType: NSUInteger | Number of objects to return. Default/Max: 100. | 
| startType: NSString | Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off. | 
| endType: NSString | Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the startparameter is supplied. | 
| blockType: PNManageChannelMembersCompletionBlock | Set channel's memberslist request completionblock. | 
Note
This method uses the builder pattern, you can remove the arguments which are optional.
Sample code
1NSArray<NSDictionary *> *uuids = @[
2  @{ 
3    @"uuid": @"uuid2"
4    @"status": @"active",
5    @"type": @"admin",
6    @"custom": @{ @"role": @"moderator" } 
7  }
8];
9
10self.client.objects().setChannelMembers(@"channel")
11    .uuids(uuids)
12    .includeCount(YES)
13    .limit(40)
14    .includeFields(PNChannelMemberCustomField | PNChannelMemberUserField)
15    .performWithCompletion(^(PNManageChannelMembersStatus *status) {
Response
Response returned by the client for set members:
1@interface PNManageChannelMembersData : PNServiceData
2
3// List of existing members.
4@property (nonatomic, readonly, strong) NSArray<PNChannelMember *> *members;
5
6// Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
7@property (nonatomic, nullable, readonly, strong) NSString *next;
8
9// Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data.
10@property (nonatomic, nullable, readonly, strong) NSString *prev;
11
12/**
13 * Total number of existing objects.
14 *
15 * Value will be 0 in case if PNChannelMembersTotalCountField not added to 'includeFields'
Remove channel members
Remove members from a Channel.
Method(s)
To Remove Channel Members you can use the following method(s) in the Objective-C SDK:
1- (void)removeChannelMembersWithRequest:(PNRemoveChannelMembersRequest *)request 
2                             completion:(nullable PNManageChannelMembersCompletionBlock)block;
| Parameter | Description | 
|---|---|
| request* | Request object for removing channel members. | 
| blockType: PNManageChannelMembersCompletionBlock | Remove channel's membersrequest completionblock. | 
PNRemoveChannelMembersRequest
| Parameter | Description | 
|---|---|
| sortType: NSArray <NSString *> | List of criteria (name of field) which should be used for sorting in ascending order. Available options are id,name, andupdated. Useascordescto specify sort direction. For example:{name: 'asc'} | 
| includeFieldsType: PNChannelMemberFields | Bitfield set to fields that should be returned with the response. Supported fields: 
 PNChannelMembersTotalCountField) can be reset by setting it to 0. | 
| filterType: NSString | Expression to filter out results basing on specified criteria. For more details on the supported grammar, check this | 
| startType: NSString | Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off. | 
| endType: NSString | Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the startparameter is supplied. | 
| limitType: NSUInteger | Number of objects to return. Default/Max: 100. | 
Sample code
1NSArray<NSString *> *uuids = @[@"uuid3", @"uuid4"];
2PNRemoveChannelMembersRequest *request = [PNRemoveChannelMembersRequest requestWithChannel:@"channel"
3                                                                                     uuids:uuids];
4// Add this request option, if returned member models should have value which has been set to
5// 'custom' and 'uuid' properties.
6request.includeFields = PNChannelMemberCustomField | PNChannelMemberUUIDField | PNChannelMembersTotalCountField;
7request.limit = 40;
8
9[self.client removeChannelMembersWithRequest:request completion:^(PNManageChannelMembersStatus *status) {
10    if (!status.isError) {
11        /**
12         * Channel's members successfully removed.
13         * Result object has following information:
14         *   result.data.members - List of channel's existing members.
15         *   result.data.next - Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
Response
Response returned by the client for remove members:
1@interface PNManageChannelMembersData : PNServiceData
2
3// List of existing members.
4@property (nonatomic, readonly, strong) NSArray<PNChannelMember *> *members;
5
6// Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
7@property (nonatomic, nullable, readonly, strong) NSString *next;
8
9// Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data.
10@property (nonatomic, nullable, readonly, strong) NSString *prev;
11
12/**
13 * Total number of existing objects.
14 *
15 * Value will be 0 in case if PNChannelMembersTotalCountField not added to 'includeFields'
Remove channel members (builder pattern)
Method(s)
1objects()
2    .removeChannelMembers(NSString *)
3    .uuids(NSArray<NSString *> *)
4    .includeFields(PNChannelMemberFields)
5    .includeCount(BOOL)
6    .filter(NSString *)
7    .sort(NSArray<NSString *> *)
8    .limit(NSUInteger)
9    .start(NSString *)
10    .end(NSString *)
11    .performWithCompletion(nullable PNManageChannelMembersCompletionBlock);
| Parameter | Description | 
|---|---|
| channel*Type: NSString | Name of channel from which members should be removed. | 
| uuidsType: NSArray | List of UUIDswhich should be removed fromchannel'slist. | 
| includeFieldsType: PNChannelMemberFields | Bitfield set to fields that should be returned with the response. Supported fields: 
 PNChannelMembersTotalCountField) can be reset by setting it to 0. | 
| includeCountType: BOOL | Whether to include the total count in the paginated response. Default: YES | 
| filterType: NSString | Expression to filter out results basing on specified criteria. For more details on the supported grammar, check this | 
| sortType: NSArray | List of criteria (name of field) which should be used for sorting in ascending order. Available options are id,name, andupdated. Useascordescto specify sort direction. For example:{name: 'asc'} | 
| limitType: NSUInteger | Number of objects to return. Default/Max: 100. | 
| startType: NSString | Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off. | 
| endType: NSString | Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the startparameter is supplied. | 
| blockType: PNManageChannelMembersCompletionBlock | Remove channel's membersrequest completionblock. | 
Note
This method uses the builder pattern, you can remove the arguments which are optional.
Sample code
1self.client.objects().removeChannelMembers(@"channel")
2    .uuids(@[@"uuid3", @"uuid4"])
3    .includeCount(YES)
4    .limit(40)
5    .includeFields(PNChannelMemberCustomField | PNChannelMemberUserField)
6    .performWithCompletion(^(PNManageChannelMembersStatus *status) {
7        if (!status.isError) {
8            /**
9             * Channel's members successfully removed.
10             * Result object has following information:
11             *   result.data.members - List of channel's existing members.
12             *   result.data.next - Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
13             *   result.data.prev - Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data.
14             *   result.data.totalCount - Total number of channel's members.
15             */
Response
Response returned by the client for remove members:
1@interface PNManageChannelMembersData : PNServiceData
2
3// List of existing members.
4@property (nonatomic, readonly, strong) NSArray<PNChannelMember *> *members;
5
6// Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
7@property (nonatomic, nullable, readonly, strong) NSString *next;
8
9// Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data.
10@property (nonatomic, nullable, readonly, strong) NSString *prev;
11
12/**
13 * Total number of existing objects.
14 *
15 * Value will be 0 in case if PNChannelMembersTotalCountField not added to 'includeFields'
Manage channel members
The method Set and Remove channel memberships for a user.
Method(s)
To Manage Channel Members you can use the following method(s) in the Objective-C SDK:
1- (void)manageChannelMembersWithRequest:(PNManageChannelMembersRequest *)request 
2                             completion:(nullable PNManageChannelMembersCompletionBlock)block;
| Parameter | Description | 
|---|---|
| request* | Request object for managing channel members. | 
| blockType: PNManageChannelMembersCompletionBlock | Manage channel's memberslist request completionblock. | 
PNManageChannelMembersRequest
| Parameter | Description | 
|---|---|
| setMembersType: NSArray <NSDictionary *> | List of UUIDs which should be added to channel's members list. Each entry is dictionary with uuid and optional customfields.customshould be dictionary with simple objects: NSString and NSNumber. | 
| removeMembersType: NSArray <NSString *> | BList of UUIDs which should be removed from channel's list. | 
| sortType: NSArray <NSString *> | List of criteria (name of field) which should be used for sorting in ascending order. Available options are id,name, andupdated. Useascordescto specify sort direction. For example:{name: 'asc'} | 
| includeFieldsType: PNChannelMemberFields | Bitfield set to fields that should be returned with the response. Supported fields: 
 PNChannelMembersTotalCountField) can be reset by setting it to 0. | 
| filterType: NSString | Expression to filter out results basing on specified criteria. For more details on the supported grammar, check this | 
| startType: NSString | Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off. | 
| endType: NSString | Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the startparameter is supplied. | 
| limitType: NSUInteger | Number of objects to return. Default/Max: 100. | 
Sample code
1PNManageChannelMembersRequest *request = [PNManageChannelMembersRequest requestWithChannel:@"channel"];
2request.setMembers = @[
3    @{ @"uuid": @"uuid2", @"custom": @{ @"role": @"moderator" } }
4];
5request.removeMembers = @[@"uuid3", @"uuid4"];
6// Add this request option, if returned member models should have value which has been set to
7// 'custom' and 'uuid' properties.
8request.includeFields = PNChannelMemberCustomField | PNChannelMemberUUIDField | PNChannelMembersTotalCountField;
9request.limit = 40;
10
11[self.client manageChannelMembersWithRequest:request
12                               completion:^(PNManageChannelMembersStatus *status) {
13
14    if (!status.isError) {
15        /**
Response
Response returned by the client for manage members:
1@interface PNManageChannelMembersData : PNServiceData
2
3// List of existing members.
4@property (nonatomic, readonly, strong) NSArray<PNChannelMember *> *members;
5
6// Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
7@property (nonatomic, nullable, readonly, strong) NSString *next;
8
9// Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data.
10@property (nonatomic, nullable, readonly, strong) NSString *prev;
11
12/**
13 * Total number of existing objects.
14 *
15 * Value will be 0 in case if PNChannelMembersTotalCountField not added to 'includeFields'
Manage channel members (builder pattern)
Method(s)
1objects()
2    .manageChannelMembers(NSString *)
3    .set(NSArray<NSDictionary *> *)
4    .remove(NSArray<NSString *> *)
5    .includeFields(PNChannelMemberFields)
6    .includeCount(BOOL)
7    .filter(NSString *)
8    .sort(NSArray<NSString *> *)
9    .limit(NSUInteger)
10    .start(NSString *)
11    .end(NSString *)
12    .performWithCompletion(nullable PNManageChannelMembersCompletionBlock);
| Parameter | Description | 
|---|---|
| channel*Type: NSString | Name of channel from which members should be managed. | 
| setType: NSArray | List of UUIDswhich should be added tochannel'smembers list. Each entry is dictionary withUUIDandoptionalcustomfields.customshould be dictionary with simple objects:NSStringandNSNumber. | 
| removeType: NSArray | List of UUIDswhich should be removed fromchannel'slist. | 
| includeFieldsType: PNChannelMemberFields | Bitfield set to fields that should be returned with the response. Supported fields: 
 PNChannelMembersTotalCountField) can be reset by setting it to 0. | 
| includeCountType: BOOL | Whether to include the total count in the paginated response. Default is false. | 
| filterType: NSString | Expression to filter out results basing on specified criteria. For more details on the supported grammar, check this | 
| sortType: NSArray | List of criteria (name of field) which should be used for sorting in ascending order. Available options are id,name, andupdated. Useascordescto specify sort direction. For example:{name: 'asc'} | 
| limitType: NSUInteger | Number of objects to return. Default/Max: 100. | 
| startType: NSString | Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off. | 
| endType: NSString | Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the startparameter is supplied. | 
| blockType: PNManageChannelMembersCompletionBlock | Set channel's memberslist request completionblock. | 
Note
This method uses the builder pattern, you can remove the arguments which are optional.
Sample code
1NSArray<NSDictionary *> *setMembers = @[
2    @{ @"uuid": @"uuid2", @"custom": @{ @"role": @"moderator" } }
3];
4NSArray<NSDictionary *> *removeMembers = @[@"uuid3", @"uuid4"];
5
6self.client.objects().manageChannelMembers(@"channel")
7    .set(setMembers)
8    .remove(removeMembers)
9    .includeCount(YES)
10    .limit(40)
11    .includeFields(PNChannelMemberCustomField | PNChannelMemberUUIDField)
12    .performWithCompletion(^(PNManageChannelMembersStatus *status) {
13        if (!status.isError) {
14            /**
15             * Channel's members successfully changed.
Response
Response returned by the client for manage members:
1@interface PNManageChannelMembersData : PNServiceData
2
3// List of existing members.
4@property (nonatomic, readonly, strong) NSArray<PNChannelMember *> *members;
5
6// Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
7@property (nonatomic, nullable, readonly, strong) NSString *next;
8
9// Random string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data.
10@property (nonatomic, nullable, readonly, strong) NSString *prev;
11
12/**
13 * Total number of existing objects.
14 *
15 * Value will be 0 in case if PNChannelMembersTotalCountField not added to 'includeFields'