Question

I am calling method that call URL with different timetstamp. However, data processing may take longer than the time I have defined.

  [self performSelector:@selector(process) withObject:nil afterDelay:1.6];

below part shows the method is called

 -(void)process
{
    timestamp=[NSString stringWithFormat:@"%1.f",progressValue];
    NSString *contour=@"&bandschema=4";
    NSString *url6=[NSString stringWithFormat:@"http://contour.php?  callback=contourData%@&type=json&timestamp=%@%@",timestamp,timestamp,contour];        
    NSURL *url1=[NSURL URLWithString:url6];
  __weak ASIHTTPRequest *request1 = [ASIHTTPRequest requestWithURL:url1];
        [request1 setCompletionBlock:^{
            responseString = [request1 responseString];
                [self plotPoint:self.responseString];

        }];
        [request1 setFailedBlock:^{

            NSError *error=[request1 error];
            NSLog(@"Error: %@", error.localizedDescription);
        }];
        [request1 startAsynchronous];
    }

this part is start point of analyzing data.

-(void)plotPoint:(NSString *)request
{
    NSArray *polygonArray = [[dict  objectForKey:@"data"]valueForKey:@"polygon"];
    NSArray *valleyPolygonArray = [[dict objectForKey:@"valley"]valueForKey:@"polygon"];
    CLLocationCoordinate2D *coords;
}

However sometimes time interval is not enough to get new data especially when internet connection is not good.

Could you guide me please? How could I handle the problem? What is the optimal solution?

Was it helpful?

Solution

Can you provide some code? Basically you need to perform the action in the request finished delegate call

Some more info here: http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSURLConnection_Class/Reference/Reference.html

http://developer.apple.com/library/mac/#documentation/Foundation/Reference/NSURLConnectionDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intf/NSURLConnectionDelegate

EDIT:
I still don't quite understand, but see if that helps you:

__weak ASIHTTPRequest *request1 = [ASIHTTPRequest requestWithURL:url1];  
        [request1 setCompletionBlock:^{  
            responseString = [request1 responseString];  
                [self plotPoint:self.responseString];  

        //if (something)  
            [self process];  
        }];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top