Lightstreamer iOS Client 1.1.1
Native iOS/Mac OS X Client library for Lightstreamer Server version 4.x and up

Getting started with the iOS Client library

The iOS Client Library has been developed using the Java SE library as a starting point. Obtaining a connection and subscribing to a table is a simple and straightforward procedure:

Creating an instance of LSClient

To create an instance of LSClient simply alloc- and init-it, or use the factory method:

LSClient *client= [[LSClient alloc] init];

Or:

LSClient *client= [LSClient client];

Open the connection

To open the connection you must first define the connection specifications using an LSConnectionInfo object, for example:

LSConnectionInfo *connectionInfo= [LSConnectionInfo connectionInfoWithPushServerURL:@"http://push.lightstreamer.com" pushServerControlURL:nil user:nil password:nil adapter:@"DEMO"];

Done this, use the LSConnectionInfo object with the LSClient:

[client openConnectionWithInfo:connectionInfo delegate:self];

Listening for connection events

Your designated delegate will then receive an event when the connection actually starts:

- (void) clientConnection:(LSClient *)client didStartSessionWithPolling:(BOOL)polling {
    ...
}

Once this happens, you can start define an LSTableInfo object that describes the table you want to subscribe:

LSTableInfo *tableInfo= [LSTableInfo tableInfoWithGroup:@"item1 item2 item3" mode:LSModeMerge schema:@"stock_name last_price min max" dataAdapter:@"QUOTE_ADAPTER" snapshot:YES];

And then subscribe it using the LSClient:

LSSubscribedTableKey *tableKey= [[_client subscribeTableWithExtendedInfo:tableInfo delegate:self useCommandLogic:NO] retain];

Remember to retain the tableKey to later unsubscribe it.

Listening for table events

Your designated table delegate will then start to receive table updates as they are sent from the Server:

- (void) table:(LSSubscribedTableKey *)tableKey itemPosition:(int)itemPosition itemName:(NSString *)itemName didUpdateWithInfo:(LSUpdateInfo *)updateInfo {
    ...
}

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

Close the connection

Remember to always close the connection before releasing LSClient (it will not be released, otherwise):

[client closeConnection];

Automatic reconnections

The library will automatic reconnect to the server in case of connection drops, timeouts, etc. Active subscriptions will also be automatically resubmitted. If you want to avoid this behavior, manually close the connection while handling appropriate events, like:

- (void) clientConnection:(LSClient *)client didReceiveServerFailure:(LSPushServerException *)failure {
    [client performSelectorInBackground:(closeConnection) withObject:nil];
}

or:

- (void) clientConnection:(LSClient *)client didReceiveConnectionFailure:(LSPushConnectionException *)failure {
    [client performSelectorInBackground:(closeConnection) withObject:nil];
}