PNClientState Class Reference

Inherits from NSObject
Declared in PNClientState.h

Overview

When client use \b state API which allow to pull and push client state, this manager stores all information locally. Locally cached data used by \b PubNub subscriber and presence modules to deliver actual cient state information to \b PubNub network.

@author Sergey Mamontov

Initialization and Configuration

+ stateForClient:

Construct state cache manager.

+ (instancetype)stateForClient:(PubNub *)client

Parameters

client

Reference on client for which state manager should be created.

Return Value

Constructed and ready to use client state cache manager.

Availability

4.0

Declared In

PNClientState.h

– inheritStateFromState:

Copy specified client’s state information.

- (void)inheritStateFromState:(PNClientState *)state

Parameters

state

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

Availability

4.0

Declared In

PNClientState.h

Information

– state

Retrieve state information stored in cache.

- (NSDictionary *)state

Return Value

Cached dictionary which store reference between remote data object names and values bound for client. \c nil will be returned in case if state cache is empty.

Availability

4.0

Discussion

State cache updated every time when client successfully subscribe on remote data object feeds with pre-defined state or modify state using corresponding API group.

Declared In

PNClientState.h

– stateMergedWith:forObjects:

Provide merged client state using new \c state information which should be bound to remote data \c object.

- (NSDictionary *)stateMergedWith:(NSDictionary *)state forObjects:(NSArray *)objects

Parameters

state

State which should be merged into client state stored in cache.

objects

List of object names for which merged data is composed. In case if merged state will have names of objects not presented in \c objects their data will be removed.

Return Value

Merged client state information

Availability

4.0

Declared In

PNClientState.h

– mergeWithState:

Merge cached client state information with the one which has been passed.

- (void)mergeWithState:(NSDictionary *)state

Parameters

state

Reference on client state information which should be merged into cached version.

Availability

4.0

Declared In

PNClientState.h

– setState:forObject:

Overwrite client state information bound to specified \c object.

- (void)setState:(NSDictionary *)state forObject:(NSString *)object

Parameters

state

State which should replace cached information.

object

Name of the object for which new data should be applied.

Availability

4.0

Declared In

PNClientState.h

– removeStateForObjects:

Clear client state cache from specified objects data.

- (void)removeStateForObjects:(NSArray *)objects

Parameters

objects

Reference on list of objects for which state should be removed.

Availability

4.0

Declared In

PNClientState.h

Extension Methods

  client

Weak reference on client for which state cache manager created.

@property (nonatomic, weak) PubNub *client

Availability

4.0

Declared In

PNClientState.m

  stateCache

Stores reference on current client state information cached from previous \b state API usage and presence events.

@property (nonatomic, strong) NSMutableDictionary *stateCache

Availability

4.0

Declared In

PNClientState.m

  resourceAccessQueue

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

@property (nonatomic, strong) dispatch_queue_t resourceAccessQueue

Availability

4.0

Declared In

PNClientState.m

– initForClient:

Construct state cache manager.

- (instancetype)initForClient:(PubNub *)client

Parameters

client

Reference on client for which state manager should be created.

Return Value

Constructed and ready to use client state cache manager.

Availability

4.0

Declared In

PNClientState.m