iOSiOSCocoaObjective-CiOS SDK V4 Publish & Subscribe API Reference for Realtime Apps

Go to Configuration


The publish function is used to send a message to all subscribers of a channel. To publish a message you must first specify a valid publishKey at initialization. A successfully published message is replicated across the PubNub Real-Time Network and sent simultaneously to all subscribed clients on a channel.
Messages in transit can be secured from potential eavesdroppers with SSL/TLS by setting ssl to true during initialization.
 
Publish Anytime
It is not required to be subscribed to a channel in order to publish to that channel.
Message Data:
The message argument can contain any JSON serializable data, including: Objects, Arrays, Ints and Strings. Message data should not contain special Objective-C classes or functions as these will not serialize. String content can include any single-byte or multi-byte UTF-8 character.
Message Size:
The maximum number of characters per message is 32K by default. The maximum message size is based on the final escaped character count, including the channel name. An ideal message size is under 1800 bytes which allows a message to be compressed and sent using single IP datagram (1.5KB) providing optimal network performance.
If the message you publish exceeds the configured size, you will receive the following message:
Message Too Large Error
["PUBLISHED",[0,"Message Too Large","13524237335750949"]]

For further details please check: https://support.pubnub.com/support/discussions/topics/14000006322

Message Publish Rate:
Messages can be published as fast as bandwidth conditions will allow. There is a soft limit based on max throughput since messages will be discarded if the subscriber cannot keep pace with the publisher.
For example, if 200 messages are published simultaneously before a subscriber has had a chance to receive any messages, the subscriber may not receive the first 100 messages because the message queue has a limit of only 100 messages stored in memory.
Publishing to Multiple Channels.
It is not possible to publish a message to multiple channels simultaneously. The message must be published to one channel at a time.
Publishing Messages Reliably.
There are some best practices to ensure messages are delivered when publishing to a channel:
  • Publish to any given channel in a serial manner (i.e. not concurrently).
  • Check that the return code is success (e.g. [1,"Sent","136074940..."])
  • Publish the next message only after receiving a success return code.
  • If a failure code is returned ([0,"blah","<timetoken>"]), retry the publish.
  • Avoid exceeding the in-memory queue's capacity of 100 messages. An overflow situation (aka missed messages) can occur if slow subscribers fail to keep up with the publish pace in a given period of time.
  • Throttle publish bursts in accordance with your app's latency needs e.g. Publish no faster than 5 msgs per second to any one channel.
 
Do Not JSON serialize!
It is important to note that you should not JSON serialize when sending signals/messages via PUBNUB. Why? Because the serialization is done for you automatically. Instead just pass the full object as the message payload. PubNub takes care of everything for you.
 

Single string messages are automatically sent to APNS if mobile push is enabled and devices are registered for push on that channel. So if you use encryption (cipher key in the init) and publish the message, then it will be sent to APNS if there is a device(s) registered to that channel.

This is a legacy feature and will be deprecated soon.

To Publish a message you can use the following method(s) in the Objective-C SDK:
  1. ParameterTypeRequiredDescription
    messageidYesReference on Foundation object ( NSString, NSNumber, NSArray, NSDictionary) which will be published.
    channelNSStringYesReference on name of the channel to which message should be published.
    blockPNPublishCompletionBlockNoPublish processing completion block which pass only one argument - request processing status to report about how data pushing was successful or not.
  2. ParameterTypeRequiredDescription
    messageidYesReference on Foundation object (NSString, NSNumber, NSArray, NSDictionary) which will be published.
    channelNSStringYesReference on name of the channel to which message should be published.
    compressedBOOLYesWhether message should be compressed and sent with request body instead of URI part. Compression useful in case if large data should be published, in another case it will lead to packet size grow.
    blockPNPublishCompletionBlockNoPublish processing completion block which pass only one argument - request processing status to report about how data pushing was successful or not.
  3. ParameterTypeRequiredDescription
    messageidYesReference on Foundation object (NSString, NSNumber, NSArray,NSDictionary) which will be published.
    channelNSStringYesReference on name of the channel to which message should be published.
    shouldStoreBOOLYesWith NO this message later won't be fetched with history API.
    blockPNPublishCompletionBlockNoPublish processing completion block which pass only one argument - request processing status to report about how data pushing was successful or not.
  4. ParameterTypeRequiredDescription
    messageidYesReference on Foundation object ( NSString, NSNumber, NSArray,NSDictionary) which will be published.
    channelNSStringYesReference on name of the channel to which message should be published.
    shouldStoreBOOLYesWith NO this message later won't be fetched with history API.
    compressedBOOLYesCompression useful in case if large data should be published, in another case it will lead to packet size grow.
    blockPNPublishCompletionBlockNoPublish processing completion block which pass only one argument - request processing status to report about how data pushing was successful or not.
  5. ParameterTypeRequiredDescription
    messageidNoReference on Foundation object (NSString, NSNumber, NSArray, NSDictionary) which will be published.
    channelNSStringYesReference on name of the channel to which message should be published.
    payloadsNSDictionaryNoDictionary with payloads for different vendors (Apple with apns key and Google with gcm).
    blockPNPublishCompletionBlockNoPublish processing completion block which pass only one argument - request processing status to report about how data pushing was successful or not.
  6. ParameterTypeRequiredDescription
    messageidNoReference on Foundation object (NSString, NSNumber, NSArray, NSDictionary) which will be published.
    channelNSStringYesReference on name of the channel to which message should be published.
    payloadsNSDictionaryYesDictionary with payloads for different vendors (Apple with apns key and Google with gcm).
    compressedBOOLYesCompression useful in case if large data should be published, in another case it will lead to packet size grow.
    blockPNPublishCompletionBlockNoPublish processing completion block which pass only one argument - request processing status to report about how data pushing was successful or not.
  7. ParameterTypeRequiredDescription
    messageidNoReference on Foundation object (NSString, NSNumber, NSArray,NSDictionary) which will be published.
    channelNSStringYesReference on name of the channel to which message should be published.
    payloadsNSDictionaryNoDictionary with payloads for different vendors (Apple with apns key and Google with gcm).
    shouldStoreBOOLYesWith NO this message later won't be fetched with history API.
    blockPNPublishCompletionBlockNoPublish processing completion block which pass only one argument - request processing status to report about how data pushing was successful or not.
  8. ParameterTypeRequiredDescription
    messageidNoReference on Foundation object (NSString, NSNumber, NSArray,NSDictionary) which will be published.
    channelNSStringYesReference on name of the channel to which message should be published.
    payloadsNSDictionaryNoDictionary with payloads for different vendors (Apple with "apns" key and Google with "gcm").
    shouldStoreBOOLYesWith NO this message later won't be fetched with history API.
    compressedBOOLYesCompression useful in case if large data should be published, in another case it will lead to packet size grow.
    blockPNPublishCompletionBlockNoPublish processing completion block which pass only one argument - request processing status to report about how data pushing was successful or not.
  9. ParameterTypeRequiredDescription
    messageidYesThe message may be any valid foundation object (String, NSNumber, Array, Dictionary).
    channelNSStringYesSpecifies channel name to publish messages to.
    metadataNSDictionaryNoNSDictionary with values which should be used by PubNub service to filter messages.
    blockPNPublishCompletionBlockNoThe completion block which will be called when the processing is complete, has one argument: - request status reports the publish was successful or not (errorData contains error information in case of failure).
  10. ParameterTypeRequiredDescription
    messageidYesThe message may be any valid foundation object (String, NSNumber, Array, Dictionary).
    channelNSStringYesSpecifies channel name to publish messages to.
    compressedBOOLYesIf true the message will be compressed and sent with request body instead of the URI. Compression useful in case of large data, in another cases it will increase the packet size.
    metadataNSDictionaryNoNSDictionary with values which should be used by PubNub service to filter messages.
    blockPNPublishCompletionBlockNoThe completion block which will be called when the processing is complete, has one argument: - request status reports the publish was successful or not (errorData contains error information in case of failure).
  11. ParameterTypeRequiredDescription
    messageidYesThe message may be any valid foundation object (String, NSNumber, Array, Dictionary).
    channelNSStringYesSpecifies channel name to publish messages to.
    shouldStoreBOOLYesIf false the messages will not be stored in history, default true.
    metadataNSDictionaryNoNSDictionary with values which should be used by PubNub service to filter messages.
    blockPNPublishCompletionBlockNoThe completion block which will be called when the processing is complete, has one argument: - request status reports the publish was successful or not (errorData contains error information in case of failure).
  12. ParameterTypeRequiredDescription
    messageidYesThe message may be any valid foundation object (String, NSNumber, Array, Dictionary).
    channelNSStringYesSpecifies channel name to publish messages to.
    shouldStoreBOOLYesIf false the messages will not be stored in history, default true.
    compressedBOOLYesIf true the message will be compressed and sent with request body instead of the URI. Compression useful in case of large data, in another cases it will increase the packet size.
    metadataNSDictionaryNoNSDictionary with values which should be used by PubNub service to filter messages.
    blockPNPublishCompletionBlockNoThe completion block which will be called when the processing is complete, has one argument: - request status reports the publish was successful or not (errorData contains error information in case of failure).
  13. ParameterTypeRequiredDescription
    messageidNoThe message may be any valid foundation object (String, NSNumber, Array, Dictionary).
    channelNSStringYesSpecifies channel name to publish messages to.
    payloadsNSDictionaryNoDictionary with payloads for different vendors (Apple with aps key and Google with gcm). Either payloads or message should be provided..
    metadataNSDictionaryNoNSDictionary with values which should be used by PubNub service to filter messages.
    blockPNPublishCompletionBlockNoThe completion block which will be called when the processing is complete, has one argument: - request status reports the publish was successful or not (errorData contains error information in case of failure).
  14. ParameterTypeRequiredDescription
    messageidNoThe message may be any valid foundation object (String, NSNumber, Array, Dictionary).
    channelNSStringYesSpecifies channel name to publish messages to.
    payloadsNSDictionaryNoDictionary with payloads for different vendors (Apple with aps key and Google with gcm). Either payloads or message should be provided.
    compressedBOOLYesIf true the message will be compressed and sent with request body instead of the URI. Compression useful in case of large data, in another cases it will increase the packet size.
    metadataNSDictionaryNoNSDictionary with values which should be used by PubNub service to filter messages.
    blockPNPublishCompletionBlockNoThe completion block which will be called when the processing is complete, has one argument: - request status reports the publish was successful or not (errorData contains error information in case of failure).
  15. ParameterTypeRequiredDescription
    messageidNoThe message may be any valid foundation object (String, NSNumber, Array, Dictionary).
    channelNSStringYesSpecifies channel name to publish messages to.
    payloadsNSDictionaryNoDictionary with payloads for different vendors (Apple with a ps key and Google with gcm). Either payloads or message should be provided.
    shouldStoreBOOLYesIf false the messages will not be stored in history, default true.
    metadataNSDictionaryNoNSDictionary with values which should be used by PubNub service to filter messages.
    blockPNPublishCompletionBlockNoThe completion block which will be called when the processing is complete, has one argument: - request status reports the publish was successful or not (errorData contains error information in case of failure).
  16. ParameterTypeRequiredDescription
    messageidNoThe message may be any valid foundation object (String, NSNumber, Array, Dictionary).
    channelNSStringYesSpecifies channel name to publish messages to.
    payloadsNSDictionaryNoDictionary with payloads for different vendors (Apple with aps key and Google with gcm). Either payloads or message should be provided.
    shouldStoreBOOLYesIf false the messages will not be stored in history, default true.
    compressedBOOLYesIf true the message will be compressed and sent with request body instead of the URI. Compression useful in case of large data, in another cases it will increase the packet size.
    metadataNSDictionaryNoNSDictionary with values which should be used by PubNub service to filter messages.
    blockPNPublishCompletionBlockNoThe completion block which will be called when the processing is complete, has one argument: - request status reports the publish was successful or not (errorData contains error information in case of failure).

Publish a message to a channel:

[self.client publish: @{@"Dictionary": @[@"with",@"array",@"as", @"value"]} 
		   toChannel: @"pubnub" withCompletion:^(PNPublishStatus *status) {
    
	if (!status.isError) {

		// Message successfully published to specified channel.
	}
	else {

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

		 Request can be resent using: [status retry];
		 */
	}
}];
 
Before running the above publish example, either using the Debug Console, or in a separate script running in a separate terminal window, subscribe to the same channel that is being published to.
Response objects which is returned by client when publish API is used:
@interface PNPublishData : PNServiceData

@property (nonatomic, readonly, strong) NSNumber *timetoken;
@property (nonatomic, readonly, strong) NSString *information;

@end

@interface PNPublishStatus : PNAcknowledgmentStatus

@property (nonatomic, readonly, strong) PNPublishData *data;

@end
  1. [self publish: @"Hello from the PubNub Objective-C" toChannel:@"chat_channel"
     withMetadata: @{@"senderID" : @"bob"}  completion:^(PNPublishStatus *status) {
    
    	if (!status.isError) {
    
    		// Message successfully published to specified channel.
    	}
    	else {
    
    		/**
    		 Handle message publish error. Check 'category' property to find 
    		 out possible reason because of which request did fail.
    		 Review 'errorData' property (which has PNErrorData data type) of status
    		 object to get additional information about issue.
    
    		 Request can be resent using: [status retry]
    		 */
    	}
    }];
This function publishes a message on a channel.
 This method uses the builder pattern, you can remove the args which are optional.
To run Publish Builder you can use the following method(s) in the Objective-C SDK
  1. ParameterTypeRequiredDescription
    messageidNoThe message may be any valid foundation object (NSString, NSNumber, NSArray, NSDictionary).
    channelNSStringYesSpecifies channel name to publish messages to.
    shouldStoreBOOLNo

    If NO the messages will not be stored in history.

    Default YES.

    replicateBOOLNoSpecify whether published message should be replicated across the PubNub Real-Time Network and sent simultaneously to all subscribed clients on a channel.
    compressBOOLNoIf YES the message will be compressed and sent with request body instead of the URI. Compression useful in case of large data, in another cases it will increase the packet size.
    ttlNSUIntegerNoSpecify for how many hours published message should be stored.
    payloadsNSDictionaryNoDictionary with payloads for different vendors (Apple with aps key and Google with gcm). Either payloads or message should be provided.
    metadataNSDictionaryNoNSDictionary with values which should be used by PubNub service to filter messages.
    blockPNPublishCompletionBlockNoThe completion block which will be called when the processing is complete, has one argument: - request status reports the publish was successful or not (errorData contains error information in case of failure).
Publish message which will be stored in channel's storage for next 16 hours.
self.client.publish().channel(@"my_channel").message(@"Hello from PubNub iOS!").shouldStore(YES).ttl(16).performWithCompletion(^(PNPublishStatus *status) {

    if (!status.isError) {

        // Message successfully published to specified channel.
    }
    else {

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

         Request can be resent using: [status retry];
         */
    }
});
The fire endpoint allows the client to send a message to BLOCKS Event Handlers. These messages will go directly to any Event Handlers registered on the channel that you fire to and will trigger their execution. The content of the fired request will be available for processing within the Event Handler. The message sent via fire() is not replicated, and so will not be received by any subscribers to the channel. The message is also not stored in history.
 This method uses the builder pattern, you can remove the args which are optional.
To Fire a message you can use the following method(s) in the Objective-C SDK
  1. ParameterTypeRequiredDescription
    messageidNoThe message may be any valid foundation object (NSString, NSNumber, NSArray, NSDictionary).
    channelNSStringYesSpecifies channel name to publish messages to.
    compressBOOLNoIf YES the message will be compressed and sent with request body instead of the URI. Compression useful in case of large data, in another cases it will increase the packet size.
    ttlNSUIntegerNoSpecify for how many hours published message should be stored.
    payloadsNSDictionaryNoDictionary with payloads for different vendors (Apple with aps key and Google with gcm). Either payloads or message should be provided.
    metadataNSDictionaryNoNSDictionary with values which should be used by PubNub service to filter messages.
    blockPNPublishCompletionBlockNoThe completion block which will be called when the processing is complete, has one argument: - request status reports the publish was successful or not (errorData contains error information in case of failure).
self.client.fire().channel(@"my_channel").message(@"Hello from PubNub iOS!").shouldStore(YES).ttl(16).performWithCompletion(^(PNPublishStatus *status) {

    if (!status.isError) {

        // Message successfully published to specified channel.
    }
    else {

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

         Request can be resent using: [status retry];
         */
    }
});
This function causes the client to create an open TCP socket to the PubNub Real-Time Network and begin listening for messages on a specified channel. To subscribe to a channel the client must send the appropriate subscribeKey at initialization.
By default a newly subscribed client will only receive messages published to the channel after the subscribeToChannels call completes.
 
You can be notified of connectivity via the connect callback. By waiting for the connect callback to return before attempting to publish, you can avoid a potential race condition on clients that subscribe and immediately publish messages before the subscribe has completed.
Using Objective-C SDK, if a client becomes disconnected from a channel, it can automatically attempt to reconnect to that channel and retrieve any available messages that were missed during that period by setting restore to YES. By default a client will attempt to reconnect after exceeding a 320 second connection timeout.
 Unsubscribing from all the channel(s) and then subscribing to a new channel Y is not the same than Subscribing to the channel Y and then unsubscribing from the previously subscribe channel(s). Unsubscribing from all the channels resets the timetoken and thus, there could be some gaps in the subscription that may lead to a message loss.
To Subscribe to a channel you can use the following method(s) in the Objective-C SDK:
  1. ParameterTypeRequiredDescription
    channelsNSArrayYesList of channel names on which client should try to subscribe.
    shouldObservePresenceBOOLYesWhether presence observation should be enabled for channels or not.
  2. ParameterTypeRequiredDescription
    channelsNSArrayYesList of channel names on which client should try to subscribe.
    shouldObservePresenceBOOLYesWhether presence observation should be enabled for channels or not.
    stateNSDictionaryNoReference on dictionary which stores key-value pairs based on channel name and value which should be assigned to it.
  3. ParameterTypeRequiredDescription
    channelsNSArrayYesList of channel names on which client should try to subscribe.
    shouldObservePresenceBOOLYesWhether presence observation should be enabled for channels or not.
    timeTokenNSNumberNoSpecifies time from which to start returning any available cached messages. Message retrieval with timetoken is not guaranteed and should only be considered a best-effort service.
  4. ParameterTypeRequiredDescription
    channelsNSArrayYesList of channel names on which client should try to subscribe.
    shouldObservePresenceBOOLYesWhether presence observation should be enabled for channels or not.
    timeTokenNSNumberNoSpecifies time from which to start returning any available cached messages. Message retrieval with timetoken is not guaranteed and should only be considered a best-effort service.
    stateNSDictionaryNoReference on dictionary which stores key-value pairs based on channel name and value which should be assigned to it.
Subscribe to a channel:
/**
 Subscription process results arrive to listener which should adopt to PNObjectEventListener protocol
 and registered using:
 */
[self.client addListener:self]; 
[self.client subscribeToChannels: @[@"my_channel1", @"my_channel2"] withPresence:NO];
 

// Handle new message from one of channels on which client has been subscribed.
- (void)client:(PubNub *)client didReceiveMessage:(PNMessageResult *)message {
    // Reference to channel group to which belong chat where message has been sent.
    NSString *subscription = message.data.subscription; 
    NSLog(@"%@ sent message to '%@' at %@: %@", message.data.publisher, message.data.channel, 
			message.data.timetoken, message.data.message);
}

// Handle subscription status change.
- (void)client:(PubNub *)client didReceiveStatus:(PNStatus *)status {
    
	if (status.operation == PNSubscribeOperation) {
        
		// Check whether received information about successful subscription or restore.
		if (status.category == PNConnectedCategory || status.category == PNReconnectedCategory) {

			// Status object for those categories can be casted to `PNSubscribeStatus` for use below.
			PNSubscribeStatus *subscribeStatus = (PNSubscribeStatus *)status;
			if (subscribeStatus.category == PNConnectedCategory) {

				// This is expected for a subscribe, this means there is no error or issue whatsoever.
			}
			else {
                
				/**
				 This usually occurs if subscribe temporarily fails but reconnects. This means there was 
				 an error but there is no longer any issue.
				 */
			}
		}
		else if (status.category == PNUnexpectedDisconnectCategory) {

			/**
			 This is usually an issue with the internet connection, this is an error, handle 
			 appropriately retry will be called automatically.
			 */
		}
		// Looks like some kind of issues happened while client tried to subscribe or disconnected from 
		// network.
		else {

			PNErrorStatus *errorStatus = (PNErrorStatus *)status;
			if (errorStatus.category == PNAccessDeniedCategory) {

				/**
				 This means that PAM does allow this client to subscribe to this channel and channel group 
				 configuration. This is another explicit error.
				 */
			}
			else {
					
				/**
				 More errors can be directly specified by creating explicit cases for other error categories 
				 of `PNStatusCategory` such as: `PNDecryptionErrorCategory`,  
				 `PNMalformedFilterExpressionCategory`, `PNMalformedResponseCategory`, `PNTimeoutCategory`
				 or `PNNetworkIssuesCategory`
				 */
			}
		}
	}
	else if (status.operation == PNUnsubscribeOperation) {

		if (status.category == PNDisconnectedCategory) {

			/**
			 This is the expected category for an unsubscribe. This means there was no error in unsubscribing
			 from everything.
			 */
		}
	}
	else if (status.operation == PNHeartbeatOperation) {

		/**
		 Heartbeat operations can in fact have errors, so it is important to check first for an error.
		 For more information on how to configure heartbeat notifications through the status 
		 PNObjectEventListener callback, consult http://www.pubnub.com/docs/ios-objective-c/api-reference-configuration#configuration_basic_usage
		 */

		if (!status.isError) { /* Heartbeat operation was successful. */ } 
		else { /* There was an error with the heartbeat operation, handle here. */ }
	}
}
@interface PNSubscriberData : PNServiceData

// Name of channel for which subscriber received data.
@property (nonatomic, readonly, strong) NSString *channel;
// Name of channel or channel group (in case if not equal to channel).
@property (nonatomic, nullable, readonly, strong) NSString *subscription;
// Time at which event arrived.
@property (nonatomic, readonly, strong) NSNumber *timetoken;
// Stores reference on metadata information which has been passed along with received event.
@property (nonatomic, nullable, readonly, strong) NSDictionary<NSString *, id> *userMetadata;

@end


@interface PNSubscribeStatus : PNErrorStatus

// Time token which has been used to establish current subscription cycle.
@property (nonatomic, readonly, strong) NSNumber *currentTimetoken;
// Stores reference on previous key which has been used in subscription cycle to receive
// currentTimetoken along with other events.
@property (nonatomic, readonly, strong) NSNumber *lastTimeToken;
// List of channels on which client currently subscribed.
@property (nonatomic, readonly, copy) NSArray<NSString *> *subscribedChannels;
//  List of channel group names on which client currently subscribed.
@property (nonatomic, readonly, copy) NSArray<NSString *> *subscribedChannelGroups;
// Structured PNResult data field information.
@property (nonatomic, readonly, strong) PNSubscriberData *data;

@end

// Message arrive to event listeners as model described below

@interface PNMessageData : PNSubscriberData

// Message sender identifier.
@property (nonatomic, readonly, strong) NSString *publisher;
// Message which has been delivered through data object live feed.
@property (nonatomic, nullable, readonly, strong) id message;

@end


@interface PNMessageResult : PNResult

// Stores reference on message object from live feed.
@property (nonatomic, readonly, strong) PNMessageData *data;

@end
  1. Requires Presence add-on XRequires that the Presence add-on is enabled for your key. See this page on enabling add-on features on your keys:

    http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys.
    For any given channel there is an associated Presence channel. You can subscribe directly to the channel by appending -pnpres to the channel name. For example the channel named my_channel would have the presence channel named my_channel-pnpres.
    /**
     Subscription process results arrive to listener which should adopt to
     PNObjectEventListener protocol and registered using:
     */
    [self.client addListener:self];
    [self.client subscribeToPresenceChannels:@[@"my_channel"]];
    
    
    // New presence event handling.
    - (void)client:(PubNub *)client didReceivePresenceEvent:(PNPresenceEventResult *)event {
    	
    	if (![event.data.channel isEqualToString:event.data.subscription]) {
    		
    		// Presence event has been received on channel group stored in event.data.subscription.
    	}
    	else {
    		
    		// Presence event has been received on channel stored in event.data.channel.
    	}
    	
    	if (![event.data.presenceEvent isEqualToString:@"state-change"]) {
    		
    		NSLog(@"%@ \"%@'ed\"\nat: %@ on %@ (Occupancy: %@)", event.data.presence.uuid, 
    			  event.data.presenceEvent, event.data.presence.timetoken, event.data.channel, 
    			  event.data.presence.occupancy);
    	}
    	else {
    		
    		NSLog(@"%@ changed state at: %@ on %@ to: %@", event.data.presence.uuid, 
    			  event.data.presence.timetoken, event.data.channel, event.data.presence.state);
    	}
    }
    {
    	"action": "join",
    	"timestamp": 1345546797,
    	"uuid": "175c2c67-b2a9-470d-8f4b-1db94f90e39e",
    	"occupancy": 2
    }
    
    {
        "action" : "leave",
        "timestamp" : 1345549797,
        "uuid" : "175c2c67-b2a9-470d-8f4b-1db94f90e39e",
        "occupancy" : 1
    }
    {
    	"action": "timeout",
    	"timestamp": 1345549797,
    	"uuid": "76c2c571-9a2b-d074-b4f8-e93e09f49bd",
    	"occupancy": 0
    }
    
    {
    	"action": "state-change",
    	"uuid": "76c2c571-9a2b-d074-b4f8-e93e09f49bd",
    	"timestamp": 1345549797,
    	"data": {
    		"isTyping": true
    	}
    }
    
    {
    	"action":"interval",
    	"timestamp":1474396578,
    	"occupancy":2
    }
    

    When a channel is in interval mode with presence_deltas pnconfig flag enabled, the interval message may also include the following fields which contain an array of changed UUIDs since the last interval message.

    • joined
    • left
    • timedout

    For example, this interval message indicates there were 2 new UUIDs that joined and 1 timed out UUID since the last interval:

    {
        "action" : "interval",
        "occupancy" : <# users in channel>,
        "timestamp" : <unix timestamp>,
        "joined" : ["uuid2", "uuid3"],
        "timedout" : ["uuid1"]
    }
    

    If the full interval message is greater than 30KB (since the max publish payload is ∼32KB), none of the extra fields will be present. Instead there will be a here_now_refresh boolean field set to true. This indicates to the user that they should do a hereNow request to get the complete list of users present in the channel.

    {
        "action" : "interval",
        "occupancy" : <# users in channel>,
        "timestamp" : <unix timestamp>,
        "here_now_refresh" : true
    }
    
  2. Requires Presence add-on XRequires that the Presence add-on is enabled for your key. See this page on enabling add-on features on your keys:

    http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys.
    // Initialize and configure PubNub client instance
    PNConfiguration *configuration = [PNConfiguration configurationWithPublishKey:@"demo" subscribeKey:@"demo"];
    self.client = [PubNub clientWithConfiguration:configuration];
    [self.client addListener:self];
    
    // Subscribe to demo channel with presence observation
    [self.client subscribeToChannels: @[@"my_channel"] withPresence:YES];
    
    - (void)client:(PubNub *)client didReceiveStatus:(PNStatus *)status {
    
        if (status.category == PNConnectedCategory) {
            [self.client setState: @{@"new": @"state"} forUUID:self.client.uuid onChannel: @"my_channel"
                   withCompletion:^(PNClientStateUpdateStatus *status) { 
                   
                if (!status.isError) {
                    // Client state successfully modified on specified channel.
                } else {
                    /**
                     Handle client state modification error. Check 'category' property
                     to find out possible reason because of which request did fail.
                     Review 'errorData' property (which has PNErrorData data type) of status
                     object to get additional information about issue.
     
                     Request can be resent using: [status retry];
                     */
                }
            }];
        }
    }
    
    // Handle new message from one of channels on which client has been subscribed.
    - (void)client:(PubNub *)client didReceiveMessage:(PNMessageResult *)message {
    
    	// Handle new message stored in message.data.message
    	if (![message.data.channel isEqualToString:message.data.subscription]) {
     
    		// Message has been received on channel group stored in message.data.subscription.
    	}
    	else {
     
    		// Message has been received on channel stored in message.data.channel.
    	}
    
    	NSLog(@"Received message: %@ on channel %@ at %@", message.data.message,
    		  message.data.channel, message.data.timetoken);
    }
    
Requires Stream Controller add-on XRequires that the Stream Controller add-on is enabled for your key. See this page on enabling add-on features on your keys:

http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys.
This functions subscribes to a channel group.
To Subscribe to a Channel Group you can use the following method(s) in the Objective-C SDK
  1. ParameterTypeRequiredDescription
    groupsNSArrayYesList of channel group names on which client should try to subscribe.
    shouldObservePresenceBOOLYesWhether presence observation should be enabled for groups or not.
  2. ParameterTypeRequiredDescription
    groupsNSArrayYesList of channel group names on which client should try to subscribe.
    shouldObservePresenceBOOLYesWhether presence observation should be enabled for groups or not.
    stateNSDictionaryNoReference on dictionary which stores key-value pairs based on channel group name and value which should be assigned to it.
Subscribe to a channel group
NSString *channelGroup = @"family";
/**
 Subscription process results arrive to listener which should adopt to 
 PNObjectEventListener protocol and registered using:
 */
[self.client addListener:self];
[self.client subscribeToChannelGroups:@[channelGroup] withPresence:NO];


// Handle new message from one of channels on which client has been subscribed.
- (void)client:(PubNub *)client didReceiveMessage:(PNMessageResult *)message {

	// Handle new message stored in message.data.message
	if (![message.data.channel isEqualToString:message.data.subscription]) {
 
		// Message has been received on channel group stored in message.data.subscription.
	}
	else {
 
		// Message has been received on channel stored in message.data.channel.
	}

	NSLog(@"Received message: %@ on channel %@ at %@", message.data.message,
		  message.data.channel, message.data.timetoken);
}

// Handle subscription status change.
- (void)client:(PubNub *)client didReceiveStatus:(PNStatus *)status {
	
	if (status.operation == PNSubscribeOperation) {
		
		// Check whether received information about successful subscription or restore.
		if (status.category == PNConnectedCategory || status.category == PNReconnectedCategory) {
			
			// Status object for those categories can be casted to `PNSubscribeStatus` for use below.
			PNSubscribeStatus *subscribeStatus = (PNSubscribeStatus *)status;
			if (subscribeStatus.category == PNConnectedCategory) {
				
				// This is expected for a subscribe, this means there is no error or issue whatsoever.
			}
			else {
				
				/**
				 This usually occurs if subscribe temporarily fails but reconnects. This means there was 
				 an error but there is no longer any issue.
				 */
			}
		}
		else if (status.category == PNUnexpectedDisconnectCategory) {
			
			/**
			 This is usually an issue with the internet connection, this is an error, handle 
			 appropriately retry will be called automatically.
			 */
		}
		// Looks like some kind of issues happened while client tried to subscribe or disconnected from 
		// network.
		else {
			
			PNErrorStatus *errorStatus = (PNErrorStatus *)status;
			if (errorStatus.category == PNAccessDeniedCategory) {
				
				/**
				 This means that PAM does allow this client to subscribe to this channel and channel group 
				 configuration. This is another explicit error.
				 */
			}
			else {
				
				/**
				 More errors can be directly specified by creating explicit cases for other error categories 
				 of `PNStatusCategory` such as: `PNDecryptionErrorCategory`,  
				 `PNMalformedFilterExpressionCategory`, `PNMalformedResponseCategory`, `PNTimeoutCategory`
				 or `PNNetworkIssuesCategory`
				 */
			}
		}
	}
}
@interface PNSubscriberData : PNServiceData

// Name of channel for which subscriber received data.
@property (nonatomic, readonly, strong) NSString *channel;
// Name of channel or channel group (in case if not equal to channel).
@property (nonatomic, nullable, readonly, strong) NSString *subscription;
// Time at which event arrived.
@property (nonatomic, readonly, strong) NSNumber *timetoken;
// Stores reference on metadata information which has been passed along with received event.
@property (nonatomic, nullable, readonly, strong) NSDictionary<NSString *, id> *userMetadata;

@end


@interface PNSubscribeStatus : PNErrorStatus

// Time token which has been used to establish current subscription cycle.
@property (nonatomic, readonly, strong) NSNumber *currentTimetoken;
// Stores reference on previous key which has been used in subscription cycle to receive
// currentTimetoken along with other events.
@property (nonatomic, readonly, strong) NSNumber *lastTimeToken;
// List of channels on which client currently subscribed.
@property (nonatomic, readonly, copy) NSArray<NSString *> *subscribedChannels;
//  List of channel group names on which client currently subscribed.
@property (nonatomic, readonly, copy) NSArray<NSString *> *subscribedChannelGroups;
// Structured PNResult data field information.
@property (nonatomic, readonly, strong) PNSubscriberData *data;

@end

// Message arrive to event listeners as model described below

@interface PNMessageData : PNSubscriberData

// Message sender identifier.
@property (nonatomic, readonly, strong) NSString *publisher;
// Message which has been delivered through data object live feed.
@property (nonatomic, nullable, readonly, strong) id message;

@end


@interface PNMessageResult : PNResult

// Stores reference on message object from live feed.
@property (nonatomic, readonly, strong) PNMessageData *data;

@end
  1. Requires Stream Controller and Presence add-on XRequires that both Stream Controller and Presence add-ons are enabled for your key. See this page on enabling add-on features on your keys:

    http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys.
    /**
     Subscription process results arrive to listener which should adopt to
     PNObjectEventListener protocol and registered using:
     */
    [self.client addListener:self];
    [self.client subscribeToChannelGroups:@[channelGroup] withPresence:YES];
    
    
    // Handle new message from one of channels on which client has been subscribed.
    - (void)client:(PubNub *)client didReceiveMessage:(PNMessageResult *)message {
    
    	// Handle new message stored in message.data.message
    	if (![message.data.channel isEqualToString:message.data.subscription]) {
     
    		// Message has been received on channel group stored in message.data.subscription.
    	}
    	else {
     
    		// Message has been received on channel stored in message.data.channel.
    	}
    
    	NSLog(@"Received message: %@ on channel %@ at %@", message.data.message,
    		  message.data.channel, message.data.timetoken);
    }
    
    // New presence event handling.
    - (void)client:(PubNub *)client didReceivePresenceEvent:(PNPresenceEventResult *)event {
    	
    	if (![event.data.channel isEqualToString:event.data.subscription]) {
    		
    		// Presence event has been received on channel group stored in event.data.subscription.
    	}
    	else {
    		
    		// Presence event has been received on channel stored in event.data.channel.
    	}
    	
    	if (![event.data.presenceEvent isEqualToString:@"state-change"]) {
    		
    		NSLog(@"%@ \"%@'ed\"\nat: %@ on %@ (Occupancy: %@)", event.data.presence.uuid, 
    			  event.data.presenceEvent, event.data.presence.timetoken, event.data.channel, 
    			  event.data.presence.occupancy);
    	}
    	else {
    		
    		NSLog(@"%@ changed state at: %@ on %@ to: %@", event.data.presence.uuid, 
    			  event.data.presence.timetoken, event.data.channel, event.data.presence.state);
    	}
    }
    
    // Handle subscription status change.
    - (void)client:(PubNub *)client didReceiveStatus:(PNStatus *)status {
    	
    	if (status.operation == PNSubscribeOperation) {
    		
    		// Check whether received information about successful subscription or restore.
    		if (status.category == PNConnectedCategory || status.category == PNReconnectedCategory) {
    			
    			// Status object for those categories can be casted to `PNSubscribeStatus` for use below.
    			PNSubscribeStatus *subscribeStatus = (PNSubscribeStatus *)status;
    			if (subscribeStatus.category == PNConnectedCategory) {
    				
    				// This is expected for a subscribe, this means there is no error or issue whatsoever.
    			}
    			else {
    				
    				/**
    				 This usually occurs if subscribe temporarily fails but reconnects. This means there was 
    				 an error but there is no longer any issue.
    				 */
    			}
    		}
    		else if (status.category == PNUnexpectedDisconnectCategory) {
    			
    			/**
    			 This is usually an issue with the internet connection, this is an error, handle 
    			 appropriately retry will be called automatically.
    			 */
    		}
    		// Looks like some kind of issues happened while client tried to subscribe or disconnected from 
    		// network.
    		else {
    			
    			PNErrorStatus *errorStatus = (PNErrorStatus *)status;
    			if (errorStatus.category == PNAccessDeniedCategory) {
    				
    				/**
    				 This means that PAM does allow this client to subscribe to this channel and channel group 
    				 configuration. This is another explicit error.
    				 */
    			}
    			else {
    				
    				/**
    				 More errors can be directly specified by creating explicit cases for other error categories 
    				 of `PNStatusCategory` such as: `PNDecryptionErrorCategory`,  
    				 `PNMalformedFilterExpressionCategory`, `PNMalformedResponseCategory`, `PNTimeoutCategory`
    				 or `PNNetworkIssuesCategory`
    				 */
    			}
    		}
    	}
    }
When subscribed to a single channel, this function causes the client to issue a leave from the channel and close any open socket to the PubNub Network. For multiplexed channels, the specified channel(s) will be removed and the socket remains open until there are no more channels remaining in the list.
 Unsubscribing from all the channel(s) and then subscribing to a new channel Y is not the same than Subscribing to the channel Y and then unsubscribing from the previously subscribe channel(s). Unsubscribing from all the channels resets the timetoken and thus, there could be some gaps in the subscription that may lead to a message loss.
To Unsubscribe from a channel you can use the following method(s) in the Objective-C SDK:
  1. ParameterTypeRequiredDescription
    channelsNSArrayYesList of channel names from which client should try to unsubscribe.
    shouldObservePresenceBOOLYesWhether client should disable presence observation on specified channels or keep listening for presence event on them.
Unsubscribe from a channel:
/**
 Unsubscription process results arrive to listener which should adopt to
 PNObjectEventListener protocol and registered using:
 */
[self.client addListener:self];
[self.client unsubscribeFromChannels: @[@"my_channel1", @"my_channel2"] withPresence:NO];

// Handle subscription status change.
- (void)client:(PubNub *)client didReceiveStatus:(PNStatus *)status {
 
	if (status.operation == PNUnsubscribeOperation && status.category == PNDisconnectedCategory) {

		/**
		 This is the expected category for an unsubscribe. This means there was no error in 
		 unsubscribing from everything.
		 */
	}
}
@interface PNSubscriberData : PNServiceData

// Name of channel for which subscriber received data.
@property (nonatomic, readonly, strong) NSString *channel;
// Name of channel or channel group (in case if not equal to channel).
@property (nonatomic, nullable, readonly, strong) NSString *subscription;
// Time at which event arrived.
@property (nonatomic, readonly, strong) NSNumber *timetoken;
// Stores reference on metadata information which has been passed along with received event.
@property (nonatomic, nullable, readonly, strong) NSDictionary<NSString *, id> *userMetadata;

@end


@interface PNSubscribeStatus : PNErrorStatus

// Time token which has been used to establish current subscription cycle.
@property (nonatomic, readonly, strong) NSNumber *currentTimetoken;
// Stores reference on previous key which has been used in subscription cycle to receive
// currentTimetoken along with other events.
@property (nonatomic, readonly, strong) NSNumber *lastTimeToken;
// List of channels on which client currently subscribed.
@property (nonatomic, readonly, copy) NSArray<NSString *> *subscribedChannels;
//  List of channel group names on which client currently subscribed.
@property (nonatomic, readonly, copy) NSArray<NSString *> *subscribedChannelGroups;
// Structured PNResult data field information.
@property (nonatomic, readonly, strong) PNSubscriberData *data;

@end
Unsubscribe from all channels and all channel groups
/**
 Unsubscription process results arrive to listener which should adopt to
 PNObjectEventListener protocol and registered using:
 */
[self.client addListener:self];
[self.client unsubscribeFromAll];

// Handle subscription status change.
- (void)client:(PubNub *)client didReceiveStatus:(PNStatus *)status {
 
	if (status.operation == PNUnsubscribeOperation && status.category == PNDisconnectedCategory) {

		/**
		 This is the expected category for an unsubscribe. This means there was no error in unsubscribing
		 from everything.
		 */
	}
}
None
This function lets you Unsubscribe from a Channel Group
To run Unsubscribe from a Channel Group you can use the following method(s) in the Objective-C SDK
  1. ParameterTypeRequiredDescription
    groupsNSArrayYesList of channel group names from which client should try to unsubscribe.
    shouldObservePresenceBOOLYesWhether client should disable presence observation on specified channel groups or keep listening for presence event on them.
/**
 Unsubscription process results arrive to listener which should adopt to
 PNObjectEventListener protocol and registered using:
 */
[self.client addListener:self];
[self.client unsubscribeFromChannelGroups: @[@"developers"] withPresence:YES];


// Handle subscription status change.
- (void)client:(PubNub *)client didReceiveStatus:(PNStatus *)status {
 
	if (status.operation == PNUnsubscribeOperation && status.category == PNDisconnectedCategory) {

		/**
		 This is the expected category for an unsubscribe. This means there was no error in unsubscribing
		 from everything.
		 */
	}
}
@interface PNSubscriberData : PNServiceData

// Name of channel for which subscriber received data.
@property (nonatomic, readonly, strong) NSString *channel;
// Name of channel or channel group (in case if not equal to channel).
@property (nonatomic, nullable, readonly, strong) NSString *subscription;
// Time at which event arrived.
@property (nonatomic, readonly, strong) NSNumber *timetoken;
// Stores reference on metadata information which has been passed along with received event.
@property (nonatomic, nullable, readonly, strong) NSDictionary<NSString *, id> *userMetadata;

@end


@interface PNSubscribeStatus : PNErrorStatus

// Time token which has been used to establish current subscription cycle.
@property (nonatomic, readonly, strong) NSNumber *currentTimetoken;
// Stores reference on previous key which has been used in subscription cycle to receive
// currentTimetoken along with other events.
@property (nonatomic, readonly, strong) NSNumber *lastTimeToken;
// List of channels on which client currently subscribed.
@property (nonatomic, readonly, copy) NSArray<NSString *> *subscribedChannels;
//  List of channel group names on which client currently subscribed.
@property (nonatomic, readonly, copy) NSArray<NSString *> *subscribedChannelGroups;
// Structured PNResult data field information.
@property (nonatomic, readonly, strong) PNSubscriberData *data;

@end
This function is used to subscribe to the presence channel.
Using Objective-C SDK, if a client becomes disconnected from a channel, it can automatically attempt to reconnect to that channel and retrieve any available messages that were missed during that period by setting restore to true. By default a client will attempt to reconnect after exceeding a 320 second connection timeout.
To do Presence you can use the following method(s) in the Objective-C SDK
  1. ParameterTypeRequiredDescription
    channelsNSArrayYesList of channel names for which client should try to subscribe on presence observing channels.
Subscribe to the presence channel:
For any given channel there is an associated Presence channel. You can subscribe directly to the channel by appending -pnpres to the channel name. For example the channel named my_channel would have the presence channel named my_channel-pnpres
/**
 Subscription process results arrive to listener which should adopt to
 PNObjectEventListener protocol and registered using:
 */
[self.client addListener:self];
[self.client subscribeToPresenceChannels:@[@"my_channel"]];


// New presence event handling.
- (void)client:(PubNub *)client didReceivePresenceEvent:(PNPresenceEventResult *)event {
	
	if (![event.data.channel isEqualToString:event.data.subscription]) {
		
		// Presence event has been received on channel group stored in event.data.subscription.
	}
	else {
		
		// Presence event has been received on channel stored in event.data.channel.
	}
	
	if (![event.data.presenceEvent isEqualToString:@"state-change"]) {
		
		NSLog(@"%@ \"%@'ed\"\nat: %@ on %@ (Occupancy: %@)", event.data.presence.uuid, 
			  event.data.presenceEvent, event.data.presence.timetoken, event.data.channel, 
			  event.data.presence.occupancy);
	}
	else {
		
		NSLog(@"%@ changed state at: %@ on %@ to: %@", event.data.presence.uuid, 
			  event.data.presence.timetoken, event.data.channel, event.data.presence.state);
	}
}
@interface PNSubscriberData : PNServiceData

// Name of channel for which subscriber received data.
@property (nonatomic, readonly, strong) NSString *channel;
// Name of channel or channel group (in case if not equal to channel).
@property (nonatomic, nullable, readonly, strong) NSString *subscription;
// Time at which event arrived.
@property (nonatomic, readonly, strong) NSNumber *timetoken;
// Stores reference on metadata information which has been passed along with received event.
@property (nonatomic, nullable, readonly, strong) NSDictionary<NSString *, id> *userMetadata;

@end


@interface PNSubscribeStatus : PNErrorStatus

// Time token which has been used to establish current subscription cycle.
@property (nonatomic, readonly, strong) NSNumber *currentTimetoken;
// Stores reference on previous key which has been used in subscription cycle to receive
// currentTimetoken along with other events.
@property (nonatomic, readonly, strong) NSNumber *lastTimeToken;
// List of channels on which client currently subscribed.
@property (nonatomic, readonly, copy) NSArray<NSString *> *subscribedChannels;
//  List of channel group names on which client currently subscribed.
@property (nonatomic, readonly, copy) NSArray<NSString *> *subscribedChannelGroups;
// Structured PNResult data field information.
@property (nonatomic, readonly, strong) PNSubscriberData *data;

@end

// Presence events arrive to event listeners as model described below

@interface PNPresenceDetailsData : PNSubscriberData

// Time when presence event has been triggered.
@property (nonatomic, readonly, strong) NSNumber *timetoken;
// Reference on unique user identifier for which event has been triggered.
@property (nonatomic, nullable, readonly, strong) NSString *uuid;
// List of newly joined subscribers' UUID.
@property (nonatomic, nullable, readonly, strong) NSArray<NSString *> *join;
// List of recently leaved subscribers' UUID.
@property (nonatomic, nullable, readonly, strong) NSArray<NSString *> *leave;
// List of recently UUID of subscribers which leaved by timeout.
@property (nonatomic, nullable, readonly, strong) NSArray<NSString *> *timeout;
// Channel presence information.
@property (nonatomic, readonly, strong) NSNumber *occupancy;
// User changed client state.
@property (nonatomic, nullable, readonly, strong) NSDictionary<NSString *, id> *state;

@end


@interface PNPresenceEventData : PNSubscriberData

// Type of presence event.
@property (nonatomic, readonly, strong) NSString *presenceEvent;
// Additional presence information.
@property (nonatomic, readonly, strong) PNPresenceDetailsData *presence;

@end

@interface PNPresenceEventResult : PNResult

// Stores reference on presence event object from live feed.
@property (nonatomic, readonly, strong) PNPresenceEventData *data;

@end
This function lets you stop monitoring the presence of the channel(s). The channel(s) will be removed and the socket remains open until there are no more channels remaining in the list.
To Unsubscribe from Presence of a channel you can use the following method(s) in the Objective-C SDK
  1. ParameterTypeRequiredDescription
    channelsNSArrayYesList of channel names for which client should try to unsubscribe from presence observing channels
Unsubscribe from the presence channel:
 [self.client unsubscribeFromChannelGroups:@[@"developers"] withPresence:YES];
@interface PNSubscriberData : PNServiceData

// Name of channel for which subscriber received data.
@property (nonatomic, readonly, strong) NSString *channel;
// Name of channel or channel group (in case if not equal to channel).
@property (nonatomic, nullable, readonly, strong) NSString *subscription;
// Time at which event arrived.
@property (nonatomic, readonly, strong) NSNumber *timetoken;
// Stores reference on metadata information which has been passed along with received event.
@property (nonatomic, nullable, readonly, strong) NSDictionary<NSString *, id> *userMetadata;

@end


@interface PNSubscribeStatus : PNErrorStatus

// Time token which has been used to establish current subscription cycle.
@property (nonatomic, readonly, strong) NSNumber *currentTimetoken;
// Stores reference on previous key which has been used in subscription cycle to receive
// currentTimetoken along with other events.
@property (nonatomic, readonly, strong) NSNumber *lastTimeToken;
// List of channels on which client currently subscribed.
@property (nonatomic, readonly, copy) NSArray<NSString *> *subscribedChannels;
//  List of channel group names on which client currently subscribed.
@property (nonatomic, readonly, copy) NSArray<NSString *> *subscribedChannelGroups;
// Structured PNResult data field information.
@property (nonatomic, readonly, strong) PNSubscriberData *data;

@end

You can be notified of connectivity status, message and presence notifications via the listeners.

Listeners should be added before calling the method.

This is list of categories which can be received by event listener:
CategoriesDescription
PNAccessDeniedCategorySubscribe request failed because of access error (active PAM). status.errorData.channels or status.errorData.channelGroups contain list of channels and/or groups to which user with specified auth key doesn't have access.
PNDecryptionErrorCategorySubscribe request returned messages which can't be decrypted with configured cipherKey. Unencrypted message will be returned in status.associatedObject where associatedObject is PNMessageData which contain channel and message properties.
PNNetworkIssuesCategorySubscribe request failed because there was no network connection at the moment when request has been sent.
PNConnectedCategorySubscribe request successfully completed and client connected to real-time data channels.
PNReconnectedCategorySubscribe request successfully completed and client has been reconnected to real-time data channels after unexpected disconnection (PNUnexpectedDisconnectCategory).
PNDisconnectedCategoryClient did unsubscribe from specified real-time data channels.
PNUnexpectedDisconnectCategoryPreviously started subscribe loop did fail and at this moment client disconnected from real-time data channels.
PNRequestMessageCountExceededCategoryIf requestMessageCountThreshold is set, this status event will arrive each time when client receive more messages when it has been specified for PNConfiguration property.
PNMalformedFilterExpressionCategorySubscription request can't be processed by PubNub service because filter expression malformed and can't be evaluated.
PNHeartbeatOperationIn case if presence heartbeat value is set, client will sent this status category at specified periods. If status.isError set to YES it mean what heartbeat request did fail (potentially because of network issues).
This is list of categories which can be received in API completion blocks (non-subscribe):
CategoriesDescription
PNAcknowledgmentCategoryUsed API report success with this status category.
PNAccessDeniedCategoryRequest failed because of access error (active PAM). status.errorData.channels or status.errorData.channelGroups contain list of channels and/or groups to which user with specified auth key doesn't have access.
PNTimeoutCategoryUsed API didn't received response from server in time.
PNNetworkIssuesCategoryAPI did fail because there was no network connection at the moment when request has been sent.
PNMalformedResponseCategoryRequest received in response non-JSON data. It can be because of publish WiFi hotspot which require authorization or proxy server message.
PNBadRequestCategoryRequest can't be completed because not all required values has been passed or passed values has unexpected data type.
PNDecryptionErrorCategoryHistory API may return this status category in case if some messages can't be decrypted. Unencrypted message will be returned in status.associatedObject where associatedObject is PNMessageData which contain channel and message properties.
PNTLSConnectionFailedCategoryTLS handshake issues and in most cases because of poor connection quality and packets loss and delays.
PNTLSUntrustedCertificateCategoryOrigin to which client tried to connect has untrusted certificate.

Go to Presence