Lightstreamer OS X Client  2.0.1
Native OS X Client library for Lightstreamer
Getting started with the iOS, OS X and tvOS Client libraries

The iOS, OS X and tvOS Client Libraries, from version 2.0 on, follow the Unified Client API model: a common API model used across all Lightstreamer client libraries.
Obtaining a connection and subscribing to a table is a simple and straightforward procedure:

Note: as of version 2.0, iOS, OS X and tvOS client libraries do not contain Mobile Push Notifications (MPN) APIs. They will be added in a subsequest release of the Unified Client API model. In the meantime, you can still have full MPN functionalities by using previous client libraries: 1.4.x for iOS, 1.2.x for OS X and 1.0.x for tvOS, which are still available and supported.

Creating an instance of LSLightstreamerClient

To create an instance of LSLightstreamerClient simply allocate and initialize it:

LSLightstreamerClient *client= [[LSLightstreamerClient alloc] initWithServerAddress:@"" adapterSet:@"MY_ADAPTER_SET"];

Setting connection parameters and start connecting

You can set additional connection parameters on LSLightstreamerClient::connectionDetails and LSLightstreamerClient::connectionOptions. E.g.:

client.connectionDetails.user= @"my_user";
[client.connectionDetails setPassword:@"my_password"];
client.connectionOptions.maxBandwidth= @"100";

Before connecting you may want to add a delegate:

[client addDelegate:self];

Done this, connect using connect (LSLightstreamerClient):

[client connect];

Please note that this call is now asynchronous: it will not block and return immeditaly. You may safely use it on the main thread. Connection progress will be notified through delegate events.

Listening for connection events

Added delegates will receive the client:didChangeStatus: (LSClientDelegate-p) event each time the connection changes its status:

- (void) client:(nonnull LSLightstreamerClient *)client didChangeStatus:(nonnull NSString *)status {
  if ([status hasPrefix:@"CONNECTED:"]) {
    // ...

Once the connection is established you will receive a notification with a status beginning with "CONNECTED:". See event documentation for more information.

Creating a subscription

You don't have to wait for a connection to be established to subscribe. You may safely subscribe in any moment, the subscription will be delivered to the server as soon as a session has been created.
To create a subscription allocate and initialize an LSSubscription instance and set its properties with the desired values:

LSSubscription *subscription= [[LSSubscription alloc] initWithSubscriptionMode:@"MERGE"];
subscription.items= @[@"my_item_1", @"my_item_2"];
subscription.fields= @[@"my_field_1", @"my_field_2"];
subscription.dataAdapter= @"MY_ADAPTER";
subscription.requestedSnapshot= @"yes";
[subscription addDelegate:self];

Once the subscription is set, subscribe using subscribe: (LSLightstreamerClient):

[client subscribe:subscription];

The library keeps memory of active subscriptions and automatically resubscribes them if the connection drops.

Listening for table events

Subscription delegates will receive the subscription:didUpdateItem: (LSSubscriptionDelegate-p) event each time an update is received:

- (void) subscription:(nonnull LSSubscription *)subscription didUpdateItem:(nonnull LSItemUpdate *)itemUpdate {
  NSString *value= [itemUpdate valueWithFieldName:"my_field_1"];
  // ...

Congratulations! Your subscription with Lightstreamer Server is now set up!

Closing the connection

To close the connection simply call disconnect (LSLightstreamerClient):

[client disconnect];