Domanda

Imagine that you are getting date from different two URLs, one is for map overlay, another one is for annotation as you can see below.There are two methods (plotAnnotations and plotOverlays) take care of JSON data and plot them on map View. I just want to make sure, is there any other way to do? How do I check/know whether or not annotations and overlays comes at the same time? I would be glad to hear any feedbacks or comments. Thanks in advance.

_weak ASIHTTPRequest *request1 = [ASIHTTPRequest requestWithURL:url1];
[request1 setCompletionBlock:^{
    NSString *responseString = [request1 responseString];
    [self plotAnnotations:responseString];

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

 __weak ASIHTTPRequest *request2 = [ASIHTTPRequest requestWithURL:url2];
[request2 setCompletionBlock:^{
    NSString *responseString2 = [request2 responseString];
    [self plotOverlays:responseString2];
}];
[request2 setFailedBlock:^{
    NSError *error=[request2 error];
    NSLog(@"Error: %@", error.localizedDescription);
}]; 

   [request2 startAsynchronous];
È stato utile?

Soluzione

You should take a look at GCD (Grand Central Dispatch). GCD docs. Create a dispatch group containing your requests, and you can use this to process both your annotations and overlays when they have both finished downloading - assuming that is what you want to do, it isn't entirely clear, but it's what your comment seems to imply.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top