Results 1 to 4 of 4
  1. #1

    Bad Access Exception when using ls lib in background thread !!!

    Hi,
    I have an exception in my app, when i put the ls connection in background thread it app throw bad access exception that i can't handle it, also i can't put the calling code in workground because it takes too long to make connection with server,
    Anyone has solution ?
    Last edited by Vahid; May 6th, 2013 at 01:34 PM.

  2. #2
    Administrator
    Join Date
    Feb 2012
    Location
    Bologna, Italy
    Posts
    102
    Hello,

    could you be more specific? What exactly do you put in background that is causing a crash? Could you post here a code snippet? The iOS client library is designed to be thread-safe and can be used from any thread, we can surely find a solution for your problem.

    Best regards,

    Gianluca

  3. #3
    Dear Gianluca,
    Thanks for your reply.
    The code is as below:


    //this line is for starting connection with lightstramer

    - (void) viewDidAppearBOOL)animated{

    if (![self isConnected]) {

    [self connectWithLightStreamer];

    }

    }



    //check ls connection status

    - (BOOL) isConnected

    {

    return client.connected;

    }




    //connect to ls in background


    - (void)connectWithLightStreamer

    {

    [self performSelectorInBackground:@selector(connectInBac kground) withObject:nil];


    }



    //connect to ls in background(private method)


    - (void) connectInBackground

    {

    client = [[LSClient alloc] init];



    LSConnectionInfo *connectioninfo = [LSConnectionInfo connectionInfoWithPushServerURL:LIGHTSTREAMER_CONN ECITON_ADDRESS pushServerControlURL:nil user:@"user" password:@"password" adapter:LIGHTSTREAMER_CONNECITON_ADAPTER];

    [client openConnectionWithInfo:connectioninfo delegate:self];

    }



    //subscribeitems

    - (void) subscribeItemsNSArray *)itemnames andTableKeyLSSubscribedTableKey *)tableKey {

    NSLog(@"StockListViewController: Subscribing table...");



    @try {

    //itemNames is equal to group

    //fieldNames is equal to schema

    LSExtendedTableInfo *tableInfo= [LSExtendedTableInfo extendedTableInfoWithItems:itemnames mode:LSModeMerge fields:fieldNames dataAdapter:LIGHTSTREAMER_CONNECITON_DATAADAPTER snapshot:YES];



    tableInfo.requestedMaxFrequency= 1.0;



    tableKey = [client subscribeTableWithExtendedInfo:tableInfo delegate:self useCommandLogic:NO];

    [self.tableKeys addObject:tableKey];

    [self.itemNames addObject:itemnames];

    NSLog(@"StockListViewController: Table subscribed");



    } @catch (NSException *e) {

    NSLog(@"StockListViewController: Table subscription failed due to exception: %@", e);

    }

    }



    //unsubscribe items

    - (void) unsubscribeItemsLSSubscribedTableKey *)tableKey {

    NSLog(@"StockListViewController: Unsubscribing table...");



    @try {

    [client unsubscribeTable:tableKey];



    [self.itemNames removeAllObjects];

    NSLog(@"StockListViewController: Table unsubscribed");



    } @catch (NSException *e) {

    NSLog(@"StockListViewController: Table unsubscription failed due to exception: %@", e);

    }

    }



    //clear ls resource(call this method when viewWillDisappear or viewDidDisappear

    - (void) clearLightStreamerResource

    {

    if (client.connected) {

    for (LSSubscribedTableKey *key in self.tableKeys) {

    [self unsubscribeItems:key];

    }

    [self.tableKeys removeAllObjects];

    [client closeConnection];

    }



    }


    Sometimes light streamer doesn’t respond when unsubscribing and causes the application stop working or freezing or crash, specifically by poor internet connectivity.
    So, I cannot use light streamer in the application with more than one page using light streamer.

    Kind Regards,
    Vahid

  4. #4
    Administrator
    Join Date
    Feb 2012
    Location
    Bologna, Italy
    Posts
    102
    Hello Vahid,

    I tested your code by putting it on a sample view controller, and it worked without problems. I can't attach files here on the forums, but feel free to contact support via e-mail and I will send it to you.

    What you should pay attention to, is reconnections. The library contains a lot of logic to reconnect automatically and restart existing subscriptions, even in poor network conditions. So, let the library do it for you. If you really want to reconnect manually, the correct way to do this is described at the Automatic reconnections paragraph of the Getting started with the iOS Client library page (i.e.: the first page) of the library's documentation. Take a look there.

    Hope this helps.
    Best regards,

    Gianluca

 

 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT +1. The time now is 02:28 PM.