Diffusion Apple API
5.9.24
Unified Client Library for iOS, OS X and tvOS
|
A client session maintains a connection to the server. To create a session use one of the open methods on the PTDiffusionSession class:
Your completion handler is called on the main dispatch queue. You must maintain a strong reference to the session instance for it to stay open, as in this example where we set the session
property on self
, which has been defined in our interface as follows:
Data in Diffusion is distributed on topics. A topic carries a single value, which can be updated. Each topic is addressed by a unique path.
The way that a session receives data is by using a subscription. These allow the session to select a particular topic, and register a delegate to handle that topic's data. A session may subscribe to many topics, as well as subscribe to the same topic multiple times.
A client session subscribes to receive topic updates using the Topics feature:
A delegate conforming to PTDiffusionTopicStreamDelegate needs to be supplied in order to handle the streaming updates once the Diffusion server has processed the subscription.
There are a couple of ways to supply this delegate but the simplest is to provide a fallback which will receive streaming updates for all topic streams which don't have an explicit delegate handler. Assuming that self
declares its conformance to the topic stream delegate protocol then it can be added as a fallback at any time like this:
An example conformant delegate protocol implementation would look like this:
Delegate messages are sent on the main dispatch queue.
It is possible to register any number of topic streams to a subscription's update events. They will each have their delegates called when a new value is received.
Changes in session state are broadcast via the default notification center for the application process. They are posted on the main dispatch queue and can be observed in the standard manner: