I am using performSelector to call URLRequest every couple of second 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×tamp=%@%@",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?
Why dont you call
processafter you get the response as follows,This way you can keep 1.6 as the exact time interval after getting a response to creating a new request.