IdentifyTask timing issue - iOS

3220
1
11-13-2015 12:22 PM
ChuckBenton
Occasional Contributor

I'm using IdentifyTask to test for parcel content being present in an existing app, specifically as follows:

I set the parameters in ParcelController, then

        NSLog(@"Fetching Parcels with params");

        [identifyTask executeWithParameters:params];

Then test results in ParcelDelegate upon completion

-(void)identifyTask:(AGSIdentifyTask *)identifyTask operation:(NSOperation *)op didExecuteWithIdentifyResults:(NSArray *)results

{

    NSLog(@"Results.count: %li", results.count);  // this is the parcel count

    if (results.count > 0) {

.

.

.

This works fine, but now I'd like to be able to provide the user a warning if no content is present, this from the MapViewController. 

I added the following at the ParcelDelegate:

-(void)identifyTask:(AGSIdentifyTask *)identifyTask operation:(NSOperation *)op didExecuteWithIdentifyResults:(NSArray *)results

{

    contentPresent = NO;

    NSLog(@"Results.count: %li", results.count);

    if (results.count > 0) {

        contentPresent = YES;

At the MapViewController I use contentPresent to alert the user if no content is available.   The problem is that contentPresent never sets as true, there appears to be a thread issue in which didExecuteWithIdentifyResults: takes a while to execute, and my if(!contentPresent) test executes before didExecuteWithIdentifyResults: is invoked.

So I added another flag in didExecuteWithIdentifyResults: (contentChecked) to allow the MapViewController to wait until didExecuteWithIdentifyResults: is invoked.  That test simply results in the system getting stuck in a endless while(!contentChecked) loop.

I inherited this app and am by no means an expert in iOS or Objective-C.  I'm using global variables for contentChecked and contentPresent and have confirmed that they are indeed visible and addressable across all areas.  It appears that the identifyTask is not executing, but only if I try to pass information out of it using the global variables.  When I remark my changes out, it all works just fine.  Is there a thread issue with identifyTask I'm missing?

Any ideas or suggestions are most welcome!

Chuck

0 Kudos
1 Reply
GagandeepSingh
Occasional Contributor II

A better approach might be as follows:

-(void)identifyTask:(AGSIdentifyTask *)identifyTask operation:(NSOperation *)op didExecuteWithIdentifyResults:(NSArray *)results

{

    //instead of using the flag

    //contentPresent = NO;

    //call the method to alert the user

    [self alertUser];

    NSLog(@"Results.count: %li", results.count);

    if (results.count > 0) {

    //instead of this

    //contentPresent = YES;

    //call a different method or add code inline, to process the results

    [self processResults:results];

    }

}

-(void)alertUser {

     //alert the user for no results

}

-(void)processResults:(NSArray*)results {

     //process the results

}

0 Kudos