2016-04-15 32 views
0

我正在使用google地方api來搜索附近的地方。我撥打一個電話獲取地點,另一個電話獲得地點的電話號碼。第二個電話會減慢應用程序的速度。任何方式在這個?如果可以提供一些示例代碼,那就太棒了。第二個Api調用正在放緩應用程序ios

s1 = [NSString stringWithFormat:@"https://api.foursquare.com/v2/venues/explore?client_id=%@&client_secret=%@&query=%@&v=20201212&m=swarm&sortByDistance=%i&radius=%f&limit=%@&ll=%f,%f", kClientID, kClientSecret, Name, sortByDistance, meterRadius, recorddisplay, lat, lng]; 

    NSLog(@"This is the foursqaure query: %@", s1); 

NSURL *jsonURL = [NSURL URLWithString:[self urlEncodeValue:s1]]; 
NSString *jsonDataString = [[NSString alloc]initWithContentsOfURL:jsonURL]; 
NSData *jsonData = [jsonDataString dataUsingEncoding:NSUTF8StringEncoding]; 
//NSLog(@"This is JSON data: %@", jsonDataString); 
if(jsonData == nil) 
{ 
    NSLog(@"SEARCH RESULT IS NIL....."); 
    //[pool release]; 
    return FALSE; 
} 
else 
{ 
    //retrieve the objects in the JSON and then make another http request... 
} 
+0

「如果可以提供一些示例代碼,那麼將會很棒」顯示_your_代碼。 – matt

+0

哦,對不起現在發佈 –

+0

在後臺線程/任務/隊列。 – trojanfoe

回答

3

此行是錯誤的:

NSString *jsonDataString = [[NSString alloc]initWithContentsOfURL:jsonURL]; 

你在主線程同步聯網。永遠不會永遠不會那樣做。這是延誤的原因。

+0

好的,謝謝。什麼是解決這個問題的方法? –

+0

如果您沒有觸摸接口或任何可能存在線程問題的對象,請將代碼移入後臺線程。更好的做法是正確地進行網絡連接,即使用NSURLSession。 – matt

+0

好的,謝謝你現在嘗試 –

相關問題