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 に答える