0
我意識到這兩個url不會同時返回數據。我想知道我如何能夠確保網址同時返回。我怎麼能夠將此代碼更改爲GCD。這是建議嗎?我在代碼中創建了調度隊列,但它沒有繪製任何東西,不工作。沒有GCD它可以工作,但它不會在同一時間返回。任何幫助,將不勝感激!多個ASIHTTPRequests
-(void)httpRequest{
_weak ASIHTTPRequest *request1 = [ASIHTTPRequest requestWithURL:url1];
[request1 setCompletionBlock:^{
NSString *responseString1 = [request1 responseString];
//dispatch_async(backgroundProcess1,^(void){
[self plotOverlay1:responseString1];
//});
}];
[request1 setFailedBlock:^{
NSError *error=[request1 error];
NSLog(@"Error: %@", error.localizedDescription);
}];
[request1 startAsynchronous];
_weak ASIHTTPRequest *request2 = [ASIHTTPRequest requestWithURL:url2];
[request2 setCompletionBlock:^{
NSString *responseString2 = [request2 responseString];
//dispatch_async(backgroundProcess2,^(void){
[self plotOverlay2:responseString2];
//});
}];
[request2 setFailedBlock:^{
NSError *error=[request2 error];
NSLog(@"Error: %@", error.localizedDescription);
}];
[request2 startAsynchronous];
}
非常感謝Jon Kroll。我非常感謝。我應該想到這個解決方案,簡單而整潔。現在我確定兩個url都能同時返回數據。我有我創建的方法(httpRequest)來調用URL的問題由計時器調用。然而,定時器每4秒調用一次(httpRequest),但是如果它執行繁重的任務,url響應不時會在同一時間匹配。例如timer = [NSTimer scheculedWith TimerInterval(4.0)target:(self)selector:@selector(httpRequest)userinfo:nil repeatats:YES]。對於這個問題,最好的解決方案是什麼?提前致謝 – casillas