开发者

How many types of URLRequest is possible in iPhone for retrieve the data from WebServices?

开发者 https://www.devze.com 2023-03-27 08:05 出处:网络
In my app i am retrieve data from web services and show in uitableview it is fine but problem is that in mu tableview suppose 10 row (that is city name and latitude longitude of all city that are in m

In my app i am retrieve data from web services and show in uitableview it is fine but problem is that in mu tableview suppose 10 row (that is city name and latitude longitude of all city that are in my table) after the retrieve city name i m trying to get Distance between user location and city so 10 times i need to call google mapAPI, in that process my app is crash. i am using NSURLRequest i had also used ASIHttpRequest - networkQueue but not get success. so how many other ways to do this? please suggest me any other types of request to fix it. thanx for any suggestion. here is my code

for (NSUInteger i=0; i<[latlongarray count]; i++) 
{
    NSString *urlString=[NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/distancematrix/json?origins=%@&destinations=%@&avoid=tolls&sensor=true",str,[latlongarray objectAtIndex:i]];
    NSLog(@"%@",urlString);
    NSURL *url = [NSURL URLWithString:urlString];
    NSURLRequest *myreque开发者_如何学JAVAst=[[NSURLRequest alloc] initWithURL:url];
    CustomConnection *distanceconnection=[[CustomConnection alloc] initWithRequest:myrequest delegate:self startImmediately:YES tag:[NSNumber numberWithInt:i]];
    [distanceconnection start];
    [distanceconnection release];
    [myrequest release];
}

str is user location, and latlongarray is array for city's location.


You can go NSURLRequest operation with either synchronous or asynchronous way. According to me, dealing with NSURLRequest asynchronously is more advisable when response being is depended for further executions.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号