我正在使用 google places api 来搜索附近的地点。我打了一个电话来获取这些地方,另一个电话来获取这些地方的电话号码。第二个电话正在减慢应用程序的速度。有办法解决这个问题吗?如果也能提供一些示例代码,那就太好了。
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...
}
最佳答案
这一行是错误的:
NSString *jsonDataString = [[NSString alloc]initWithContentsOfURL:jsonURL];
您正在主线程上同步联网。永远永远永远不要那样做。这就是延迟的原因。
关于ios - 第二个 Api 调用正在减慢应用程序 ios,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36652548/