第二次Api通话正在减慢app ios的速度

时间:2016-04-15 16:38:44

标签: ios objective-c api

我正在使用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...
}

1 个答案:

答案 0 :(得分:3)

这一行错了:

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

您在主线程上同步联网。永远不要永远不要那样做。这是造成延误的原因。

相关问题