PNStateListener Class Reference

Inherits from NSObject
Declared in PNStateListener.h

Overview

Subscriber manager work in pair with state listener manager. Using manager’s ability user able to add multiple listeners for state events which is triggered on subscriber. Listeners may receive events about new message or presence event on one of remote data objects live feed. Also listeners will receive subscriber state change (connected, disconnected, unexpected disconnect and etc).

@author Sergey Mamontov

Initialization and Configuration

+ stateListenerForClient:

Construct state listener manager for concrete \b PubNub client instance.

+ (instancetype)stateListenerForClient:(PubNub *)client

Parameters

client

Reference on client for which manager should operate and use data.

Return Value

Constructed and ready to use state listener manager.

Availability

4.0

Declared In

PNStateListener.h

– inheritStateFromListener:

Copy specified listener’s state information.

- (void)inheritStateFromListener:(PNStateListener *)listener

Parameters

listener

Reference on state listener manager whose information should be copied into receiver’s state objects.

Availability

4.0

Declared In

PNStateListener.h

Listeners list modification

– addListener:

Add observer which conform to \b PNObjectEventListener protocol and would like to receive updates based on live feed events and status change.

- (void)addListener:(id<PNObjectEventListener>)listener

Parameters

listener

Listener which would like to receive updates.

Availability

4.0

Discussion

Listener can implement only required callbacks from \b PNObjectEventListener protocol and called only when desired type of event arrive.

Declared In

PNStateListener.h

– removeListener:

Remove listener from list for callback calls.

- (void)removeListener:(id<PNObjectEventListener>)listener

Parameters

listener

Listener which doesn’t want to receive updates anymore.

Availability

4.0

Discussion

When listener not interested in live feed updates it can remove itself from updates list using this method.

Declared In

PNStateListener.h

– removeAllListeners

Remove all registered listeners (for message, presence event and client state change).

- (void)removeAllListeners

Availability

4.0

Declared In

PNStateListener.h

Listeners notification

– notifyWithBlock:

This method allow to shift execution context temporary to private protected queue which will serialize access to list of listeners.

- (void)notifyWithBlock:(dispatch_block_t)block

Parameters

block

Reference on block which will be called on private queue.

Availability

4.0

Declared In

PNStateListener.h

– notifyMessage:withStatus:

Notify all message listeners about new message.

- (void)notifyMessage:(PNMessageResult *)message withStatus:(PNErrorStatus *)status

Parameters

message

Reference on event object which provide information about operation type and service response for it.

status

Additional status object used to notify listenres about possible issues with received message.

Availability

4.0

Discussion

Warning: Method should be called within \b notifyWithBlock: block to shift execution to private protected queue.

Declared In

PNStateListener.h

– notifyPresenceEvent:

Notify all presence event listeners about new event.

- (void)notifyPresenceEvent:(PNPresenceEventResult *)event

Parameters

event

Reference on event object which provide information about operation type and service response for it.

Availability

4.0

Discussion

Warning: Method should be called within \b notifyWithBlock: block to shift execution to private protected queue.

Declared In

PNStateListener.h

– notifyStatusChange:

Notify all state change listeners about changes in subscriber state.

- (void)notifyStatusChange:(PNSubscribeStatus *)status

Parameters

status

Reference on state object which describe operation and category.

Availability

4.0

Discussion

Warning: Method should be called within \b notifyWithBlock: block to shift execution to private protected queue.

Declared In

PNStateListener.h

Extension Methods

  client

Weak reference on client for which state listeners manager created.

@property (nonatomic, weak) PubNub *client

Availability

4.0

Declared In

PNStateListener.m

  messageListeners

Stores list of listeners which would like to be notified when new message arrive from remote data feed objects on which client subscrubed at this moment.

@property (nonatomic, strong) NSHashTable *messageListeners

Return Value

Hash table with list of new message listeners.

Availability

4.0

Declared In

PNStateListener.m

  presenceEventListeners

Stores list of listeners which would like to be notified when new presence event arrive from remote data feed objects on which client subscrubed at this moment.

@property (nonatomic, strong) NSHashTable *presenceEventListeners

Return Value

Hash table with list of presence event listeners.

Availability

4.0

Declared In

PNStateListener.m

  stateListeners

Stores list of listeners which would like to be notified when on subscription state changes (connection, access rights error, disconnection and unexpected disconnection).

@property (nonatomic, strong) NSHashTable *stateListeners

Availability

4.0

Declared In

PNStateListener.m

  resourceAccessQueue

Stores reference on queue which is used to serialize access to shared listener information.

@property (nonatomic, strong) dispatch_queue_t resourceAccessQueue

Availability

4.0

Declared In

PNStateListener.m

– initForClient:

Initialize state listener manager for concrete \b PubNub client instance.

- (instancetype)initForClient:(PubNub *)client

Parameters

client

Reference on client for which manager should operate and use data.

Return Value

Initialized and ready to use state listener manager.

Availability

4.0

Declared In

PNStateListener.m