### Add PubNub Listener - Objective-C Source: https://github.com/pubnub/objective-c/blob/master/README.md Demonstrates how to add an object conforming to the `PNEventsListener` protocol to the PubNub client instance to start receiving events. The listener object will receive callbacks for various PubNub events. ```objectivec // Listener's class should conform to `PNEventsListener` protocol // in order to have access to available callbacks. // Adding listener. [pubnub addListener:self]; ``` -------------------------------- ### Initialize and Configure PubNub Client Source: https://github.com/pubnub/objective-c/blob/master/README.md This Objective-C snippet demonstrates how to initialize and configure a PubNub client instance. It uses PNConfiguration to set the publish key, subscribe key, and a unique UUID before creating the PubNub client. ```Objective-C // Initialize and configure PubNub client instance PNConfiguration *configuration = [PNConfiguration configurationWithPublishKey: @"myPublishKey" subscribeKey:@"mySubscribeKey"]; configuration.uuid = @"myUniqueUUID"; self.client = [PubNub clientWithConfiguration:configuration]; ``` -------------------------------- ### Publishing and Subscribing with PubNub Objective-C Source: https://github.com/pubnub/objective-c/blob/master/README.md Demonstrates how to publish a simple message to a specified channel and how to subscribe to a list of channels with presence enabled using the PubNub Objective-C client. Includes basic error handling for the publish operation. ```Objective-C [self.client publish:@{ @ "msg": @"hello" } toChannel:targetChannel withCompletion:^(PNPublishStatus *publishStatus) { if (!publishStatus.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: [publishStatus retry]; */ } }]; [self.client subscribeToChannels: @[@"hello-world-channel"] withPresence:YES]; ``` -------------------------------- ### Handle PubNub File Event - Objective-C Source: https://github.com/pubnub/objective-c/blob/master/README.md Implements the `client:didReceiveFileEvent:` callback to process file upload events. It demonstrates extracting channel, subscription, associated message, publisher, and file details like download URL, identifier, and name. ```objectivec - (void)client:(PubNub *)pubnub didReceiveFileEvent:(PNFileEventResult *)event { NSString *channel = event.data.channel; // Channel to which file has been uploaded NSString *subscription = event.data.subscription; // Wild-card channel or channel on which PubNub client actually subscribed id message = event.data.message; // Message added for uploaded file NSString *publisher = event.data.publisher; // UUID of file uploader NSURL *fileDownloadURL = event.data.file.downloadURL; // URL which can be used to download file NSString *fileIdentifier = event.data.file.identifier; // Unique file identifier NSString *fileName = event.data.file.name; // Name with which file has been stored remotely } ``` -------------------------------- ### Handle PubNub Message Event - Objective-C Source: https://github.com/pubnub/objective-c/blob/master/README.md Implements the `client:didReceiveMessage:` callback to process incoming messages. It shows how to extract key message details like channel, subscription, timetoken, payload, and publisher from the `PNMessageResult` object. ```objectivec - (void)client:(PubNub *)pubnub didReceiveMessage:(PNMessageResult *)message { NSString *channel = message.data.channel; // Channel on which the message has been published NSString *subscription = message.data.subscription; // Wild-card channel or channel on which PubNub client actually subscribed NSNumber *timetoken = message.data.timetoken; // Publish timetoken id msg = message.data.message; // Message payload NSString *publisher = message.data.publisher; // Message publisher } ``` -------------------------------- ### Configure PubNub Pod Dependency in Podfile Source: https://github.com/pubnub/objective-c/blob/master/README.md This Groovy snippet shows how to add the PubNub SDK as a dependency in a CocoaPods Podfile for an iOS project targeting version 9.0 or later. It specifies the use of frameworks and the PubNub pod version. ```Groovy platform :ios, '9.0' target 'application-target-name' do use_frameworks! pod "PubNub", "~> 4" end ``` -------------------------------- ### Handle PubNub Presence Event - Objective-C Source: https://github.com/pubnub/objective-c/blob/master/README.md Implements the `client:didReceivePresenceEvent:` callback to process presence changes (join, leave, state-change, timeout, interval). It shows how to access event type, occupancy, timetoken, UUID, and state/interval-specific details. ```objectivec - (void)client:(PubNub *)pubnub didReceivePresenceEvent:(PNPresenceEventResult *)event { NSString *channel = message.data.channel; // Channel on which presence changes NSString *subscription = message.data.subscription; // Wild-card channel or channel on which PubNub client actually subscribed NSString *presenceEvent = event.data.presenceEvent; // Can be: join, leave, state-change, timeout or interval NSNumber *occupancy = event.data.presence.occupancy; // Number of users subscribed to the channel (not available for state-change event) NSNumber *timetoken = event.data.presence.timetoken; // Presence change timetoken NSString *uuid = event.data.presence.uuid; // UUID of user for which presence change happened // Only for 'state-change' event NSDictionary *state = event.data.presence.state; // User state (only for state-change event) // Only for 'interval' event NSArray *join = event.data.presence.join; // UUID of users which recently joined channel NSArray *leave = event.data.presence.leave; // UUID of users which recently leaved channel NSArray *timeout = event.data.presence.timeout; // UUID of users which recently timed out on channel } ``` -------------------------------- ### Handle PubNub Signal Event - Objective-C Source: https://github.com/pubnub/objective-c/blob/master/README.md Implements the `client:didReceiveSignal:` callback to process incoming signals. It shows how to extract key signal details like channel, subscription, timetoken, payload, and publisher from the `PNSignalResult` object. ```objectivec - (void)client:(PubNub *)pubnub didReceiveSignal:(PNSignalResult *)signal { NSString *channel = message.data.channel; // Channel on which the signal has been published NSString *subscription = message.data.subscription; // Wild-card channel or channel on which PubNub client actually subscribed NSNumber *timetoken = message.data.timetoken; // Signal timetoken id msg = message.data.message; // Signal payload NSString *publisher = message.data.publisher; // Signal publisher } ``` -------------------------------- ### Handle PubNub Object Event - Objective-C Source: https://github.com/pubnub/objective-c/blob/master/README.md Implements the `client:didReceiveObjectEvent:` callback to process object metadata updates (channel, UUID, membership). It shows how to extract the event type, entity type, timestamp, and the relevant updated metadata object. ```objectivec - (void)client:(PubNub *)pubnub didReceiveObjectEvent:(PNObjectEventResult *)event { NSString *channel = event.data.channel; // Channel to which the event belongs NSString *subscription = event.data.subscription; // Wild-card channel or channel on which PubNub client actually subscribed NSString *event = event.data.event; // Can be: set or delete NSString *type = event.data.type; // Entity type: channel, uuid or membership NSNumber *timestamp = event.data.timestamp; // Event timestamp PNChannelMetadata *channelMetadata = event.data.channelMetadata; // Updated channel metadata (only for channel entity type) PNUUIDMetadata *uuidMetadata = event.data.uuidMetadata; // Updated channel metadata (only for uuid entity type) PNMembership *membership = event.data.membership; // Updated channel metadata (only for membership entity type) } ``` -------------------------------- ### Handle PubNub Message Action Event - Objective-C Source: https://github.com/pubnub/objective-c/blob/master/README.md Implements the `client:didReceiveMessageAction:` callback to process message action events (add/remove). It demonstrates extracting action details such as type, value, associated message timetoken, action timetoken, and the UUID of the user who performed the action. ```objectivec - (void)client:(PubNub *)pubnub didReceiveMessageAction:(PNMessageActionResult *)action { NSString *channel = action.data.channel; // Channel on which the message has been published NSString *subscription = action.data.subscription; // Wild-card channel or channel on which PubNub client actually subscribed NSString *event = action.data.event; // Can be: added or removed NSString *type = action.data.action.type; // Message action type NSString *value = action.data.action.value; // Message action value NSNumber *messageTimetoken = action.data.action.messageTimetoken; // Timetoken of the original message NSNumber *actionTimetoken = action.data.action.actionTimetoken; // Timetoken of the message action NSString *uuid = action.data.action.uuid; // UUID of user which added / removed message action } ``` -------------------------------- ### Handle PubNub Status Event - Objective-C Source: https://github.com/pubnub/objective-c/blob/master/README.md Implements the `client:didReceiveStatus:` callback to process status updates from the PubNub client. This callback is crucial for monitoring the connection state and operation outcomes. Note: The provided snippet is incomplete. ```objectivec - (void)client:(PubNub *)pubnub didReceiveStatus:(PNStatus *)status { ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.