1

我正在使用 performSelector 每隔几秒使用不同的时间戳调用 URLRequest。但是,数据处理可能需要比我定义的时间更长的时间。

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

下面的部分显示了该方法被调用

 -(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];
    }

这部分是分析数据的起点。

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

然而,有时时间间隔不足以获取新数据,尤其是当互联网连接不好时。

你能指导我吗?我该如何处理这个问题?最佳解决方案是什么?

4

1 回答 1

0

process收到如下回复后为什么不打电话,

-(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];

            if (somecondition)//based on some condition to break the chain when needed
              [self process];    
        }];
        [request1 setFailedBlock:^{

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

            if (somecondition)//based on some condition to break the chain when needed
              [self process];        
        }];
        [request1 startAsynchronous];
    }

这样,您可以在获得对创建新请求的响应后将 1.6 作为确切的时间间隔。

于 2012-11-13T00:42:15.967 回答